@@ -264,7 +264,7 @@ impl Ponger {
264264
265265 if let Some ( ref mut ka) = self . keep_alive {
266266 ka. maybe_schedule ( is_idle, & locked) ;
267- ka. maybe_ping ( cx, & mut locked) ;
267+ ka. maybe_ping ( cx, is_idle , & mut locked) ;
268268 }
269269
270270 if !locked. is_ping_sent ( ) {
@@ -284,7 +284,7 @@ impl Ponger {
284284 if let Some ( ref mut ka) = self . keep_alive {
285285 locked. update_last_read_at ( ) ;
286286 ka. maybe_schedule ( is_idle, & locked) ;
287- ka. maybe_ping ( cx, & mut locked) ;
287+ ka. maybe_ping ( cx, is_idle , & mut locked) ;
288288 }
289289
290290 if let Some ( ref mut bdp) = self . bdp {
@@ -448,7 +448,7 @@ impl KeepAlive {
448448 self . timer . reset ( & mut self . sleep , interval) ;
449449 }
450450
451- fn maybe_ping ( & mut self , cx : & mut task:: Context < ' _ > , shared : & mut Shared ) {
451+ fn maybe_ping ( & mut self , cx : & mut task:: Context < ' _ > , is_idle : bool , shared : & mut Shared ) {
452452 match self . state {
453453 KeepAliveState :: Scheduled ( at) => {
454454 if Pin :: new ( & mut self . sleep ) . poll ( cx) . is_pending ( ) {
@@ -460,6 +460,10 @@ impl KeepAlive {
460460 cx. waker ( ) . wake_by_ref ( ) ; // schedule us again
461461 return ;
462462 }
463+ if !self . while_idle && is_idle {
464+ trace ! ( "keep-alive no need to ping when idle and while_idle=false" ) ;
465+ return ;
466+ }
463467 trace ! ( "keep-alive interval ({:?}) reached" , self . interval) ;
464468 shared. send_ping ( ) ;
465469 self . state = KeepAliveState :: PingSent ;
0 commit comments