diff --git a/src/client/mod.rs b/src/client/mod.rs index d3726907ab..ea2615af19 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -376,13 +376,9 @@ impl Clone for HyperClient { } } -impl self::pool::Ready for HyperClient { - fn poll_ready(&mut self) -> Poll<(), ()> { - if self.tx.is_closed() { - Err(()) - } else { - Ok(Async::Ready(())) - } +impl self::pool::Closed for HyperClient { + fn is_closed(&self) -> bool { + self.tx.is_closed() } } diff --git a/src/client/pool.rs b/src/client/pool.rs index e5e12b1a4e..ed5ff497ea 100644 --- a/src/client/pool.rs +++ b/src/client/pool.rs @@ -21,8 +21,8 @@ pub struct Pool { // This is a trait to allow the `client::pool::tests` to work for `i32`. // // See https://github.com/hyperium/hyper/issues/1429 -pub trait Ready { - fn poll_ready(&mut self) -> Poll<(), ()>; +pub trait Closed { + fn is_closed(&self) -> bool; } struct PoolInner { @@ -49,7 +49,7 @@ struct PoolInner { expired_timer_spawned: bool, } -impl Pool { +impl Pool { pub fn new(enabled: bool, timeout: Option) -> Pool { Pool { inner: Rc::new(RefCell::new(PoolInner { @@ -117,10 +117,10 @@ impl Pool { let mut should_remove = false; let entry = inner.idle.get_mut(key).and_then(|list| { trace!("take; url = {:?}, expiration = {:?}", key, expiration.0); - while let Some(mut entry) = list.pop() { + while let Some(entry) = list.pop() { match entry.status.get() { TimedKA::Idle(idle_at) if !expiration.expires(idle_at) => { - if let Ok(Async::Ready(())) = entry.value.poll_ready() { + if !entry.value.is_closed() { should_remove = list.is_empty(); return Some(entry); } @@ -202,7 +202,9 @@ impl Pool { inner.parked.remove(key); } } +} +impl Pool { fn clear_expired(&self) { let mut inner = self.inner.borrow_mut(); @@ -218,6 +220,9 @@ impl Pool { inner.idle.retain(|_key, values| { values.retain(|val| { + if val.value.is_closed() { + return false; + } match val.status.get() { TimedKA::Idle(idle_at) if now - idle_at < dur => { true @@ -234,7 +239,7 @@ impl Pool { } -impl Pool { +impl Pool { pub(super) fn spawn_expired_interval(&self, handle: &Handle) { let mut inner = self.inner.borrow_mut(); @@ -296,7 +301,7 @@ impl DerefMut for Pooled { } } -impl KeepAlive for Pooled { +impl KeepAlive for Pooled { fn busy(&mut self) { self.entry.status.set(TimedKA::Busy); } @@ -347,7 +352,7 @@ impl fmt::Debug for Pooled { } } -impl BitAndAssign for Pooled { +impl BitAndAssign for Pooled { fn bitand_assign(&mut self, enabled: bool) { if !enabled { self.disable(); @@ -377,13 +382,13 @@ pub struct Checkout { struct NotParked; -impl Checkout { +impl Checkout { fn poll_parked(&mut self) -> Poll, NotParked> { let mut drop_parked = false; if let Some(ref mut rx) = self.parked { match rx.poll() { Ok(Async::Ready(mut entry)) => { - if let Ok(Async::Ready(())) = entry.value.poll_ready() { + if !entry.value.is_closed() { return Ok(Async::Ready(self.pool.reuse(&self.key, entry))); } drop_parked = true; @@ -408,7 +413,7 @@ impl Checkout { } } -impl Future for Checkout { +impl Future for Checkout { type Item = Pooled; type Error = io::Error; @@ -456,7 +461,7 @@ struct IdleInterval { pool: Weak>>, } -impl Future for IdleInterval { +impl Future for IdleInterval { type Item = (); type Error = (); @@ -478,14 +483,14 @@ impl Future for IdleInterval { mod tests { use std::rc::Rc; use std::time::Duration; - use futures::{Async, Future, Poll}; + use futures::{Async, Future}; use futures::future; use proto::KeepAlive; - use super::{Ready, Pool}; + use super::{Closed, Pool}; - impl Ready for i32 { - fn poll_ready(&mut self) -> Poll<(), ()> { - Ok(Async::Ready(())) + impl Closed for i32 { + fn is_closed(&self) -> bool { + false } }