Skip to content

Commit

Permalink
feat(client): add support to set SO_NODELAY on client HTTP sockets
Browse files Browse the repository at this point in the history
Add configuration on `HttpConnector` to set `SO_NODELAY` on client
HTTP sockets.

Closes #1473
  • Loading branch information
tee-too committed Apr 16, 2018
1 parent b0f4485 commit 016d79e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/client/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ pub struct HttpConnector {
enforce_http: bool,
handle: Option<Handle>,
keep_alive_timeout: Option<Duration>,
nodelay: bool,
}

impl HttpConnector {
Expand Down Expand Up @@ -205,6 +206,7 @@ impl HttpConnector {
enforce_http: true,
handle,
keep_alive_timeout: None,
nodelay: false,
}
}

Expand All @@ -225,6 +227,14 @@ impl HttpConnector {
pub fn set_keepalive(&mut self, dur: Option<Duration>) {
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 {
Expand Down Expand Up @@ -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,
}
}
}
Expand All @@ -274,6 +285,7 @@ fn invalid_url(err: InvalidUrl, handle: &Option<Handle>) -> HttpConnecting {
state: State::Error(Some(io::Error::new(io::ErrorKind::InvalidInput, err))),
handle: handle.clone(),
keep_alive_timeout: None,
nodelay: false,
}
}

Expand Down Expand Up @@ -306,6 +318,7 @@ pub struct HttpConnecting {
state: State,
handle: Option<Handle>,
keep_alive_timeout: Option<Duration>,
nodelay: bool,
}

enum State {
Expand Down Expand Up @@ -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")),
Expand Down

0 comments on commit 016d79e

Please sign in to comment.