mirror of
https://github.com/OMGeeky/tarpc.git
synced 2026-02-13 21:18:18 +01:00
Set a default max packet size. (#128)
The default max packet size of 2 << 20
This commit is contained in:
@@ -27,14 +27,40 @@ cfg_if! {
|
||||
}
|
||||
|
||||
/// Additional options to configure how the client connects and operates.
|
||||
#[derive(Default)]
|
||||
pub struct Options {
|
||||
/// Max packet size in bytes.
|
||||
max_payload_size: u64,
|
||||
reactor: Option<Reactor>,
|
||||
#[cfg(feature = "tls")]
|
||||
tls_ctx: Option<Context>,
|
||||
}
|
||||
|
||||
impl Default for Options {
|
||||
#[cfg(feature = "tls")]
|
||||
fn default() -> Self {
|
||||
Options {
|
||||
max_payload_size: 2 << 20,
|
||||
reactor: None,
|
||||
tls_ctx: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "tls"))]
|
||||
fn default() -> Self {
|
||||
Options {
|
||||
max_payload_size: 2 << 20,
|
||||
reactor: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Options {
|
||||
/// Set the max payload size in bytes. The default is 2,000,000 (2 MB).
|
||||
pub fn max_payload_size(mut self, bytes: u64) -> Self {
|
||||
self.max_payload_size = bytes;
|
||||
self
|
||||
}
|
||||
|
||||
/// Drive using the given reactor handle. Only used by `FutureClient`s.
|
||||
pub fn handle(mut self, handle: reactor::Handle) -> Self {
|
||||
self.reactor = Some(Reactor::Handle(handle));
|
||||
@@ -106,12 +132,12 @@ impl<Req, Resp, E> Client<Req, Resp, E>
|
||||
Resp: Deserialize + 'static,
|
||||
E: Deserialize + 'static
|
||||
{
|
||||
fn bind(handle: &reactor::Handle, tcp: StreamType) -> Self
|
||||
fn bind(handle: &reactor::Handle, tcp: StreamType, max_payload_size: u64) -> Self
|
||||
where Req: Serialize + Sync + Send + 'static,
|
||||
Resp: Deserialize + Sync + Send + 'static,
|
||||
E: Deserialize + Sync + Send + 'static
|
||||
{
|
||||
let inner = Proto::new().bind_client(&handle, tcp);
|
||||
let inner = Proto::new(max_payload_size).bind_client(&handle, tcp);
|
||||
Client { inner }
|
||||
}
|
||||
|
||||
@@ -161,6 +187,8 @@ impl<Req, Resp, E> ClientExt for Client<Req, Resp, E>
|
||||
#[cfg(feature = "tls")]
|
||||
let tls_ctx = options.tls_ctx.take();
|
||||
|
||||
let max_payload_size = options.max_payload_size;
|
||||
|
||||
let connect = move |handle: &reactor::Handle| {
|
||||
let handle2 = handle.clone();
|
||||
TcpStream::connect(&addr, handle)
|
||||
@@ -180,7 +208,7 @@ impl<Req, Resp, E> ClientExt for Client<Req, Resp, E>
|
||||
#[cfg(not(feature = "tls"))]
|
||||
future::ok(StreamType::Tcp(socket))
|
||||
})
|
||||
.map(move |tcp| Client::bind(&handle2, tcp))
|
||||
.map(move |tcp| Client::bind(&handle2, tcp, max_payload_size))
|
||||
};
|
||||
let (tx, rx) = futures::oneshot();
|
||||
let setup = move |handle: &reactor::Handle| {
|
||||
|
||||
Reference in New Issue
Block a user