Enable TCP nodelay by default (#860)

This commit is contained in:
Sean McArthur
2020-03-25 12:38:29 -07:00
committed by GitHub
parent 84a560a4fa
commit 1f834714f0
2 changed files with 34 additions and 6 deletions

View File

@@ -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
}

View File

@@ -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.