From 016d79ed2633e3f939a2cd10454cbfc5882effb4 Mon Sep 17 00:00:00 2001 From: tee-too Date: Mon, 16 Apr 2018 13:28:22 +0200 Subject: [PATCH] feat(client): add support to set SO_NODELAY on client HTTP sockets Add configuration on `HttpConnector` to set `SO_NODELAY` on client HTTP sockets. Closes #1473 --- src/client/connect.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/client/connect.rs b/src/client/connect.rs index ca261d86..99541717 100644 --- a/src/client/connect.rs +++ b/src/client/connect.rs @@ -170,6 +170,7 @@ pub struct HttpConnector { enforce_http: bool, handle: Option, keep_alive_timeout: Option, + nodelay: bool, } impl HttpConnector { @@ -205,6 +206,7 @@ impl HttpConnector { enforce_http: true, handle, keep_alive_timeout: None, + nodelay: false, } } @@ -225,6 +227,14 @@ impl HttpConnector { pub fn set_keepalive(&mut self, dur: Option) { self.keep_alive_timeout = dur; } + + /// Set that all sockets have `SO_NODELAY` set to the supplied value `nodelay`. + /// + /// Default is `false`. + #[inline] + pub fn set_nodelay(&mut self, nodelay: bool) { + self.nodelay = nodelay; + } } impl fmt::Debug for HttpConnector { @@ -264,6 +274,7 @@ impl Connect for HttpConnector { state: State::Lazy(self.executor.clone(), host.into(), port), handle: self.handle.clone(), keep_alive_timeout: self.keep_alive_timeout, + nodelay: self.nodelay, } } } @@ -274,6 +285,7 @@ fn invalid_url(err: InvalidUrl, handle: &Option) -> HttpConnecting { state: State::Error(Some(io::Error::new(io::ErrorKind::InvalidInput, err))), handle: handle.clone(), keep_alive_timeout: None, + nodelay: false, } } @@ -306,6 +318,7 @@ pub struct HttpConnecting { state: State, handle: Option, keep_alive_timeout: Option, + nodelay: bool, } enum State { @@ -355,6 +368,8 @@ impl Future for HttpConnecting { sock.set_keepalive(Some(dur))?; } + sock.set_nodelay(self.nodelay)?; + return Ok(Async::Ready((sock, Connected::new()))); }, State::Error(ref mut e) => return Err(e.take().expect("polled more than once")),