1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use super::ipc_handler::{unix_socket, Connect};
use crate::error::{ClientErrorKind, Result};
use derivative::Derivative;
use parsec_interface::requests::{Request, Response};
use std::time::Duration;
const DEFAULT_MAX_BODY_SIZE: usize = usize::max_value();
#[derive(Derivative)]
#[derivative(Debug)]
pub struct RequestClient {
pub max_body_size: usize,
#[derivative(Debug = "ignore")]
pub ipc_handler: Box<dyn Connect + Send + Sync>,
}
impl RequestClient {
pub fn process_request(&self, request: Request) -> Result<Response> {
let mut stream = self.ipc_handler.connect()?;
request
.write_to_stream(&mut stream)
.map_err(ClientErrorKind::Interface)?;
Ok(Response::read_from_stream(&mut stream, self.max_body_size)
.map_err(ClientErrorKind::Interface)?)
}
}
impl Default for RequestClient {
fn default() -> Self {
RequestClient {
max_body_size: DEFAULT_MAX_BODY_SIZE,
ipc_handler: Box::from(unix_socket::Handler::default()),
}
}
}
impl crate::BasicClient {
pub fn set_max_body_size(&mut self, max_body_size: usize) {
self.op_client.request_client.max_body_size = max_body_size;
}
pub fn set_ipc_handler(&mut self, ipc_handler: Box<dyn Connect + Send + Sync>) {
self.op_client.request_client.ipc_handler = ipc_handler;
}
pub fn set_timeout(&mut self, timeout: Option<Duration>) {
self.op_client
.request_client
.ipc_handler
.set_timeout(timeout);
}
}