From 1f834714f01e3e41cf4afd836eadd46b8a73351a Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Wed, 25 Mar 2020 12:38:29 -0700 Subject: [PATCH] Enable TCP nodelay by default (#860) --- src/async_impl/client.rs | 22 ++++++++++++++++++---- src/blocking/client.rs | 18 ++++++++++++++++-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index 1a7968f..55b1ffd 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -137,7 +137,7 @@ impl ClientBuilder { http2_initial_stream_window_size: None, http2_initial_connection_window_size: None, local_address: None, - nodelay: false, + nodelay: true, trust_dns: cfg!(feature = "trust-dns"), #[cfg(feature = "cookies")] cookie_store: None, @@ -630,9 +630,23 @@ impl ClientBuilder { // TCP options - /// Set that all sockets have `SO_NODELAY` set to `true`. - pub fn tcp_nodelay(mut self) -> ClientBuilder { - self.config.nodelay = true; + #[doc(hidden)] + #[deprecated(note = "tcp_nodelay is enabled by default, use `tcp_nodelay_` to disable")] + pub fn tcp_nodelay(self) -> ClientBuilder { + self.tcp_nodelay_(true) + } + + /// Set whether sockets have `SO_NODELAY` enabled. + /// + /// Default is `true`. + // NOTE: Regarding naming (trailing underscore): + // + // Due to the original `tcp_nodelay()` not taking an argument, changing + // the default means a user has no way of *disabling* this feature. + // + // TODO(v0.11.x): Remove trailing underscore. + pub fn tcp_nodelay_(mut self, enabled: bool) -> ClientBuilder { + self.config.nodelay = enabled; self } diff --git a/src/blocking/client.rs b/src/blocking/client.rs index 447c2cf..dcd1871 100644 --- a/src/blocking/client.rs +++ b/src/blocking/client.rs @@ -327,9 +327,23 @@ impl ClientBuilder { // TCP options - /// Set that all sockets have `SO_NODELAY` set to `true`. + #[doc(hidden)] + #[deprecated(note = "tcp_nodelay is enabled by default, use `tcp_nodelay_` to disable")] pub fn tcp_nodelay(self) -> ClientBuilder { - self.with_inner(move |inner| inner.tcp_nodelay()) + self.tcp_nodelay_(true) + } + + /// Set whether sockets have `SO_NODELAY` enabled. + /// + /// Default is `true`. + // NOTE: Regarding naming (trailing underscore): + // + // Due to the original `tcp_nodelay()` not taking an argument, changing + // the default means a user has no way of *disabling* this feature. + // + // TODO(v0.11.x): Remove trailing underscore. + pub fn tcp_nodelay_(self, enabled: bool) -> ClientBuilder { + self.with_inner(move |inner| inner.tcp_nodelay_(enabled)) } /// Bind to a local IP Address.