@@ -21,8 +21,8 @@ pub struct Pool<T> {
2121// This is a trait to allow the `client::pool::tests` to work for `i32`.
2222//
2323// See https://github.com/hyperium/hyper/issues/1429
24- pub trait Ready {
25- fn poll_ready ( & mut self ) -> Poll < ( ) , ( ) > ;
24+ pub trait Closed {
25+ fn is_closed ( & self ) -> bool ;
2626}
2727
2828struct PoolInner < T > {
@@ -49,7 +49,7 @@ struct PoolInner<T> {
4949 expired_timer_spawned : bool ,
5050}
5151
52- impl < T : Clone + Ready > Pool < T > {
52+ impl < T : Clone + Closed > Pool < T > {
5353 pub fn new ( enabled : bool , timeout : Option < Duration > ) -> Pool < T > {
5454 Pool {
5555 inner : Rc :: new ( RefCell :: new ( PoolInner {
@@ -117,10 +117,10 @@ impl<T: Clone + Ready> Pool<T> {
117117 let mut should_remove = false ;
118118 let entry = inner. idle . get_mut ( key) . and_then ( |list| {
119119 trace ! ( "take; url = {:?}, expiration = {:?}" , key, expiration. 0 ) ;
120- while let Some ( mut entry) = list. pop ( ) {
120+ while let Some ( entry) = list. pop ( ) {
121121 match entry. status . get ( ) {
122122 TimedKA :: Idle ( idle_at) if !expiration. expires ( idle_at) => {
123- if let Ok ( Async :: Ready ( ( ) ) ) = entry. value . poll_ready ( ) {
123+ if ! entry. value . is_closed ( ) {
124124 should_remove = list. is_empty ( ) ;
125125 return Some ( entry) ;
126126 }
@@ -202,7 +202,9 @@ impl<T> Pool<T> {
202202 inner. parked . remove ( key) ;
203203 }
204204 }
205+ }
205206
207+ impl < T : Closed > Pool < T > {
206208 fn clear_expired ( & self ) {
207209 let mut inner = self . inner . borrow_mut ( ) ;
208210
@@ -218,6 +220,9 @@ impl<T> Pool<T> {
218220 inner. idle . retain ( |_key, values| {
219221
220222 values. retain ( |val| {
223+ if val. value . is_closed ( ) {
224+ return false ;
225+ }
221226 match val. status . get ( ) {
222227 TimedKA :: Idle ( idle_at) if now - idle_at < dur => {
223228 true
@@ -234,7 +239,7 @@ impl<T> Pool<T> {
234239}
235240
236241
237- impl < T : ' static > Pool < T > {
242+ impl < T : Closed + ' static > Pool < T > {
238243 pub ( super ) fn spawn_expired_interval ( & self , handle : & Handle ) {
239244 let mut inner = self . inner . borrow_mut ( ) ;
240245
@@ -296,7 +301,7 @@ impl<T> DerefMut for Pooled<T> {
296301 }
297302}
298303
299- impl < T : Clone + Ready > KeepAlive for Pooled < T > {
304+ impl < T : Clone + Closed > KeepAlive for Pooled < T > {
300305 fn busy ( & mut self ) {
301306 self . entry . status . set ( TimedKA :: Busy ) ;
302307 }
@@ -347,7 +352,7 @@ impl<T> fmt::Debug for Pooled<T> {
347352 }
348353}
349354
350- impl < T : Clone + Ready > BitAndAssign < bool > for Pooled < T > {
355+ impl < T : Clone + Closed > BitAndAssign < bool > for Pooled < T > {
351356 fn bitand_assign ( & mut self , enabled : bool ) {
352357 if !enabled {
353358 self . disable ( ) ;
@@ -377,13 +382,13 @@ pub struct Checkout<T> {
377382
378383struct NotParked ;
379384
380- impl < T : Clone + Ready > Checkout < T > {
385+ impl < T : Clone + Closed > Checkout < T > {
381386 fn poll_parked ( & mut self ) -> Poll < Pooled < T > , NotParked > {
382387 let mut drop_parked = false ;
383388 if let Some ( ref mut rx) = self . parked {
384389 match rx. poll ( ) {
385390 Ok ( Async :: Ready ( mut entry) ) => {
386- if let Ok ( Async :: Ready ( ( ) ) ) = entry. value . poll_ready ( ) {
391+ if ! entry. value . is_closed ( ) {
387392 return Ok ( Async :: Ready ( self . pool . reuse ( & self . key , entry) ) ) ;
388393 }
389394 drop_parked = true ;
@@ -408,7 +413,7 @@ impl<T: Clone + Ready> Checkout<T> {
408413 }
409414}
410415
411- impl < T : Clone + Ready > Future for Checkout < T > {
416+ impl < T : Clone + Closed > Future for Checkout < T > {
412417 type Item = Pooled < T > ;
413418 type Error = io:: Error ;
414419
@@ -456,7 +461,7 @@ struct IdleInterval<T> {
456461 pool : Weak < RefCell < PoolInner < T > > > ,
457462}
458463
459- impl < T : ' static > Future for IdleInterval < T > {
464+ impl < T : Closed + ' static > Future for IdleInterval < T > {
460465 type Item = ( ) ;
461466 type Error = ( ) ;
462467
@@ -478,14 +483,14 @@ impl<T: 'static> Future for IdleInterval<T> {
478483mod tests {
479484 use std:: rc:: Rc ;
480485 use std:: time:: Duration ;
481- use futures:: { Async , Future , Poll } ;
486+ use futures:: { Async , Future } ;
482487 use futures:: future;
483488 use proto:: KeepAlive ;
484- use super :: { Ready , Pool } ;
489+ use super :: { Closed , Pool } ;
485490
486- impl Ready for i32 {
487- fn poll_ready ( & mut self ) -> Poll < ( ) , ( ) > {
488- Ok ( Async :: Ready ( ( ) ) )
491+ impl Closed for i32 {
492+ fn is_closed ( & self ) -> bool {
493+ false
489494 }
490495 }
491496
0 commit comments