Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed Nov 1, 2023
1 parent 0a4725e commit 5b10d40
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/proto/h2/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl Ponger {

if let Some(ref mut ka) = self.keep_alive {
ka.maybe_schedule(is_idle, &locked);
ka.maybe_ping(cx, &mut locked);
ka.maybe_ping(cx, is_idle, &mut locked);
}

if !locked.is_ping_sent() {
Expand All @@ -284,7 +284,7 @@ impl Ponger {
if let Some(ref mut ka) = self.keep_alive {
locked.update_last_read_at();
ka.maybe_schedule(is_idle, &locked);
ka.maybe_ping(cx, &mut locked);
ka.maybe_ping(cx, is_idle, &mut locked);
}

if let Some(ref mut bdp) = self.bdp {
Expand Down Expand Up @@ -448,7 +448,7 @@ impl KeepAlive {
self.timer.reset(&mut self.sleep, interval);
}

fn maybe_ping(&mut self, cx: &mut task::Context<'_>, shared: &mut Shared) {
fn maybe_ping(&mut self, cx: &mut task::Context<'_>, is_idle: bool, shared: &mut Shared) {
match self.state {
KeepAliveState::Scheduled(at) => {
if Pin::new(&mut self.sleep).poll(cx).is_pending() {
Expand All @@ -460,6 +460,10 @@ impl KeepAlive {
cx.waker().wake_by_ref(); // schedule us again
return;
}
if !self.while_idle && is_idle {
trace!("keep-alive no need to ping when idle and while_idle=false");
return;
}
trace!("keep-alive interval ({:?}) reached", self.interval);
shared.send_ping();
self.state = KeepAliveState::PingSent;
Expand Down

0 comments on commit 5b10d40

Please sign in to comment.