@@ -21,8 +21,8 @@ pub struct Pool<T> {
21
21
// This is a trait to allow the `client::pool::tests` to work for `i32`.
22
22
//
23
23
// 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 ;
26
26
}
27
27
28
28
struct PoolInner < T > {
@@ -49,7 +49,7 @@ struct PoolInner<T> {
49
49
expired_timer_spawned : bool ,
50
50
}
51
51
52
- impl < T : Clone + Ready > Pool < T > {
52
+ impl < T : Clone + Closed > Pool < T > {
53
53
pub fn new ( enabled : bool , timeout : Option < Duration > ) -> Pool < T > {
54
54
Pool {
55
55
inner : Rc :: new ( RefCell :: new ( PoolInner {
@@ -117,10 +117,10 @@ impl<T: Clone + Ready> Pool<T> {
117
117
let mut should_remove = false ;
118
118
let entry = inner. idle . get_mut ( key) . and_then ( |list| {
119
119
trace ! ( "take; url = {:?}, expiration = {:?}" , key, expiration. 0 ) ;
120
- while let Some ( mut entry) = list. pop ( ) {
120
+ while let Some ( entry) = list. pop ( ) {
121
121
match entry. status . get ( ) {
122
122
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 ( ) {
124
124
should_remove = list. is_empty ( ) ;
125
125
return Some ( entry) ;
126
126
}
@@ -202,7 +202,9 @@ impl<T> Pool<T> {
202
202
inner. parked . remove ( key) ;
203
203
}
204
204
}
205
+ }
205
206
207
+ impl < T : Closed > Pool < T > {
206
208
fn clear_expired ( & self ) {
207
209
let mut inner = self . inner . borrow_mut ( ) ;
208
210
@@ -218,6 +220,9 @@ impl<T> Pool<T> {
218
220
inner. idle . retain ( |_key, values| {
219
221
220
222
values. retain ( |val| {
223
+ if val. value . is_closed ( ) {
224
+ return false ;
225
+ }
221
226
match val. status . get ( ) {
222
227
TimedKA :: Idle ( idle_at) if now - idle_at < dur => {
223
228
true
@@ -234,7 +239,7 @@ impl<T> Pool<T> {
234
239
}
235
240
236
241
237
- impl < T : ' static > Pool < T > {
242
+ impl < T : Closed + ' static > Pool < T > {
238
243
pub ( super ) fn spawn_expired_interval ( & self , handle : & Handle ) {
239
244
let mut inner = self . inner . borrow_mut ( ) ;
240
245
@@ -296,7 +301,7 @@ impl<T> DerefMut for Pooled<T> {
296
301
}
297
302
}
298
303
299
- impl < T : Clone + Ready > KeepAlive for Pooled < T > {
304
+ impl < T : Clone + Closed > KeepAlive for Pooled < T > {
300
305
fn busy ( & mut self ) {
301
306
self . entry . status . set ( TimedKA :: Busy ) ;
302
307
}
@@ -347,7 +352,7 @@ impl<T> fmt::Debug for Pooled<T> {
347
352
}
348
353
}
349
354
350
- impl < T : Clone + Ready > BitAndAssign < bool > for Pooled < T > {
355
+ impl < T : Clone + Closed > BitAndAssign < bool > for Pooled < T > {
351
356
fn bitand_assign ( & mut self , enabled : bool ) {
352
357
if !enabled {
353
358
self . disable ( ) ;
@@ -377,13 +382,13 @@ pub struct Checkout<T> {
377
382
378
383
struct NotParked ;
379
384
380
- impl < T : Clone + Ready > Checkout < T > {
385
+ impl < T : Clone + Closed > Checkout < T > {
381
386
fn poll_parked ( & mut self ) -> Poll < Pooled < T > , NotParked > {
382
387
let mut drop_parked = false ;
383
388
if let Some ( ref mut rx) = self . parked {
384
389
match rx. poll ( ) {
385
390
Ok ( Async :: Ready ( mut entry) ) => {
386
- if let Ok ( Async :: Ready ( ( ) ) ) = entry. value . poll_ready ( ) {
391
+ if ! entry. value . is_closed ( ) {
387
392
return Ok ( Async :: Ready ( self . pool . reuse ( & self . key , entry) ) ) ;
388
393
}
389
394
drop_parked = true ;
@@ -408,7 +413,7 @@ impl<T: Clone + Ready> Checkout<T> {
408
413
}
409
414
}
410
415
411
- impl < T : Clone + Ready > Future for Checkout < T > {
416
+ impl < T : Clone + Closed > Future for Checkout < T > {
412
417
type Item = Pooled < T > ;
413
418
type Error = io:: Error ;
414
419
@@ -456,7 +461,7 @@ struct IdleInterval<T> {
456
461
pool : Weak < RefCell < PoolInner < T > > > ,
457
462
}
458
463
459
- impl < T : ' static > Future for IdleInterval < T > {
464
+ impl < T : Closed + ' static > Future for IdleInterval < T > {
460
465
type Item = ( ) ;
461
466
type Error = ( ) ;
462
467
@@ -478,14 +483,14 @@ impl<T: 'static> Future for IdleInterval<T> {
478
483
mod tests {
479
484
use std:: rc:: Rc ;
480
485
use std:: time:: Duration ;
481
- use futures:: { Async , Future , Poll } ;
486
+ use futures:: { Async , Future } ;
482
487
use futures:: future;
483
488
use proto:: KeepAlive ;
484
- use super :: { Ready , Pool } ;
489
+ use super :: { Closed , Pool } ;
485
490
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
489
494
}
490
495
}
491
496
0 commit comments