Merge pull request #1487 from tee-too/issue-1473
feat(client): add support to set SO_NODELAY on client HTTP sockets
This commit is contained in:
@@ -170,6 +170,7 @@ pub struct HttpConnector {
|
|||||||
enforce_http: bool,
|
enforce_http: bool,
|
||||||
handle: Option<Handle>,
|
handle: Option<Handle>,
|
||||||
keep_alive_timeout: Option<Duration>,
|
keep_alive_timeout: Option<Duration>,
|
||||||
|
nodelay: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HttpConnector {
|
impl HttpConnector {
|
||||||
@@ -205,6 +206,7 @@ impl HttpConnector {
|
|||||||
enforce_http: true,
|
enforce_http: true,
|
||||||
handle,
|
handle,
|
||||||
keep_alive_timeout: None,
|
keep_alive_timeout: None,
|
||||||
|
nodelay: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,6 +227,14 @@ impl HttpConnector {
|
|||||||
pub fn set_keepalive(&mut self, dur: Option<Duration>) {
|
pub fn set_keepalive(&mut self, dur: Option<Duration>) {
|
||||||
self.keep_alive_timeout = dur;
|
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 {
|
impl fmt::Debug for HttpConnector {
|
||||||
@@ -264,6 +274,7 @@ impl Connect for HttpConnector {
|
|||||||
state: State::Lazy(self.executor.clone(), host.into(), port),
|
state: State::Lazy(self.executor.clone(), host.into(), port),
|
||||||
handle: self.handle.clone(),
|
handle: self.handle.clone(),
|
||||||
keep_alive_timeout: self.keep_alive_timeout,
|
keep_alive_timeout: self.keep_alive_timeout,
|
||||||
|
nodelay: self.nodelay,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -274,6 +285,7 @@ fn invalid_url(err: InvalidUrl, handle: &Option<Handle>) -> HttpConnecting {
|
|||||||
state: State::Error(Some(io::Error::new(io::ErrorKind::InvalidInput, err))),
|
state: State::Error(Some(io::Error::new(io::ErrorKind::InvalidInput, err))),
|
||||||
handle: handle.clone(),
|
handle: handle.clone(),
|
||||||
keep_alive_timeout: None,
|
keep_alive_timeout: None,
|
||||||
|
nodelay: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,6 +318,7 @@ pub struct HttpConnecting {
|
|||||||
state: State,
|
state: State,
|
||||||
handle: Option<Handle>,
|
handle: Option<Handle>,
|
||||||
keep_alive_timeout: Option<Duration>,
|
keep_alive_timeout: Option<Duration>,
|
||||||
|
nodelay: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum State {
|
enum State {
|
||||||
@@ -355,6 +368,8 @@ impl Future for HttpConnecting {
|
|||||||
sock.set_keepalive(Some(dur))?;
|
sock.set_keepalive(Some(dur))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sock.set_nodelay(self.nodelay)?;
|
||||||
|
|
||||||
return Ok(Async::Ready((sock, Connected::new())));
|
return Ok(Async::Ready((sock, Connected::new())));
|
||||||
},
|
},
|
||||||
State::Error(ref mut e) => return Err(e.take().expect("polled more than once")),
|
State::Error(ref mut e) => return Err(e.take().expect("polled more than once")),
|
||||||
|
|||||||
Reference in New Issue
Block a user