diff --git a/src/client/mod.rs b/src/client/mod.rs index 5a9bc61fc2..50bd0d7914 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -145,6 +145,8 @@ pub struct Config { connect_timeout: Duration, connector: C, keep_alive: bool, + keep_alive_timeout: Option, + //TODO: make use of max_idle config max_idle: usize, max_sockets: usize, } @@ -157,6 +159,7 @@ impl Config where C: Connect + Send + 'static { connect_timeout: self.connect_timeout, connector: val, keep_alive: self.keep_alive, + keep_alive_timeout: Some(Duration::from_secs(60 * 2)), max_idle: self.max_idle, max_sockets: self.max_sockets, } @@ -171,6 +174,17 @@ impl Config where C: Connect + Send + 'static { self } + /// Set an optional timeout for idle sockets being kept-alive. + /// + /// Pass `None` to disable timeout. + /// + /// Default is 2 minutes. + #[inline] + pub fn keep_alive_timeout(mut self, val: Option) -> Config { + self.keep_alive_timeout = val; + self + } + /// Set the max table size allocated for holding on to live sockets. /// /// Default is 1024. @@ -202,6 +216,7 @@ impl Default for Config { connect_timeout: Duration::from_secs(10), connector: DefaultConnector::default(), keep_alive: true, + keep_alive_timeout: Some(Duration::from_secs(60 * 2)), max_idle: 5, max_sockets: 1024, } diff --git a/src/server/mod.rs b/src/server/mod.rs index 85654e77a3..c3a5dbd188 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -40,7 +40,7 @@ impl> fmt::Debug for ServerLoop { pub struct Server { listener: T, keep_alive: bool, - idle_timeout: Duration, + idle_timeout: Option, max_sockets: usize, } @@ -51,7 +51,7 @@ impl Server where T: Accept, T::Output: Transport { Server { listener: listener, keep_alive: true, - idle_timeout: Duration::from_secs(10), + idle_timeout: Some(Duration::from_secs(10)), max_sockets: 4096, } } @@ -67,7 +67,7 @@ impl Server where T: Accept, T::Output: Transport { /// Sets how long an idle connection will be kept before closing. /// /// Default is 10 seconds. - pub fn idle_timeout(mut self, val: Duration) -> Server { + pub fn idle_timeout(mut self, val: Option) -> Server { self.idle_timeout = val; self }