feat(client): add keep_alive_timeout to Client

This commit is contained in:
Sean McArthur
2016-07-14 17:24:19 -07:00
parent 02cb96ac2d
commit 976218badc
2 changed files with 18 additions and 3 deletions

View File

@@ -145,6 +145,8 @@ pub struct Config<C> {
connect_timeout: Duration,
connector: C,
keep_alive: bool,
keep_alive_timeout: Option<Duration>,
//TODO: make use of max_idle config
max_idle: usize,
max_sockets: usize,
}
@@ -157,6 +159,7 @@ impl<C> Config<C> 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<C> Config<C> 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<Duration>) -> Config<C> {
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<DefaultConnector> {
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,
}