@@ -264,7 +264,7 @@ impl Ponger {
264
264
265
265
if let Some ( ref mut ka) = self . keep_alive {
266
266
ka. maybe_schedule ( is_idle, & locked) ;
267
- ka. maybe_ping ( cx, & mut locked) ;
267
+ ka. maybe_ping ( cx, is_idle , & mut locked) ;
268
268
}
269
269
270
270
if !locked. is_ping_sent ( ) {
@@ -284,7 +284,7 @@ impl Ponger {
284
284
if let Some ( ref mut ka) = self . keep_alive {
285
285
locked. update_last_read_at ( ) ;
286
286
ka. maybe_schedule ( is_idle, & locked) ;
287
- ka. maybe_ping ( cx, & mut locked) ;
287
+ ka. maybe_ping ( cx, is_idle , & mut locked) ;
288
288
}
289
289
290
290
if let Some ( ref mut bdp) = self . bdp {
@@ -448,7 +448,7 @@ impl KeepAlive {
448
448
self . timer . reset ( & mut self . sleep , interval) ;
449
449
}
450
450
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 ) {
452
452
match self . state {
453
453
KeepAliveState :: Scheduled ( at) => {
454
454
if Pin :: new ( & mut self . sleep ) . poll ( cx) . is_pending ( ) {
@@ -460,6 +460,10 @@ impl KeepAlive {
460
460
cx. waker ( ) . wake_by_ref ( ) ; // schedule us again
461
461
return ;
462
462
}
463
+ if !self . while_idle && is_idle {
464
+ trace ! ( "keep-alive no need to ping when idle and while_idle=false" ) ;
465
+ return ;
466
+ }
463
467
trace ! ( "keep-alive interval ({:?}) reached" , self . interval) ;
464
468
shared. send_ping ( ) ;
465
469
self . state = KeepAliveState :: PingSent ;
0 commit comments