Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client): add support to set SO_NODELAY on client HTTP sockets #1487

Merged
merged 1 commit into from
Apr 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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