Skip to content

Commit 016d79e

Browse files
committed
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
1 parent b0f4485 commit 016d79e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/client/connect.rs

+15
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ pub struct HttpConnector {
170170
enforce_http: bool,
171171
handle: Option<Handle>,
172172
keep_alive_timeout: Option<Duration>,
173+
nodelay: bool,
173174
}
174175

175176
impl HttpConnector {
@@ -205,6 +206,7 @@ impl HttpConnector {
205206
enforce_http: true,
206207
handle,
207208
keep_alive_timeout: None,
209+
nodelay: false,
208210
}
209211
}
210212

@@ -225,6 +227,14 @@ impl HttpConnector {
225227
pub fn set_keepalive(&mut self, dur: Option<Duration>) {
226228
self.keep_alive_timeout = dur;
227229
}
230+
231+
/// Set that all sockets have `SO_NODELAY` set to the supplied value `nodelay`.
232+
///
233+
/// Default is `false`.
234+
#[inline]
235+
pub fn set_nodelay(&mut self, nodelay: bool) {
236+
self.nodelay = nodelay;
237+
}
228238
}
229239

230240
impl fmt::Debug for HttpConnector {
@@ -264,6 +274,7 @@ impl Connect for HttpConnector {
264274
state: State::Lazy(self.executor.clone(), host.into(), port),
265275
handle: self.handle.clone(),
266276
keep_alive_timeout: self.keep_alive_timeout,
277+
nodelay: self.nodelay,
267278
}
268279
}
269280
}
@@ -274,6 +285,7 @@ fn invalid_url(err: InvalidUrl, handle: &Option<Handle>) -> HttpConnecting {
274285
state: State::Error(Some(io::Error::new(io::ErrorKind::InvalidInput, err))),
275286
handle: handle.clone(),
276287
keep_alive_timeout: None,
288+
nodelay: false,
277289
}
278290
}
279291

@@ -306,6 +318,7 @@ pub struct HttpConnecting {
306318
state: State,
307319
handle: Option<Handle>,
308320
keep_alive_timeout: Option<Duration>,
321+
nodelay: bool,
309322
}
310323

311324
enum State {
@@ -355,6 +368,8 @@ impl Future for HttpConnecting {
355368
sock.set_keepalive(Some(dur))?;
356369
}
357370

371+
sock.set_nodelay(self.nodelay)?;
372+
358373
return Ok(Async::Ready((sock, Connected::new())));
359374
},
360375
State::Error(ref mut e) => return Err(e.take().expect("polled more than once")),

0 commit comments

Comments
 (0)