(re)start the idle timer when sending an ACK-eliciting packet
Spec says that we need to restart idle timer when sending an
ACK-eliciting packet, but only if we haven't sent an ACK-eliciting
packet since last receiving a packet.
diff --git a/src/lib.rs b/src/lib.rs
index 0deb182..44b51ff 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -689,6 +689,10 @@
/// Whether the connection handshake has been confirmed.
handshake_confirmed: bool,
+ /// Whether an ACK-eliciting packet has been sent since last receiving a
+ /// packet.
+ ack_eliciting_sent: bool,
+
/// Whether the connection is closed.
closed: bool,
@@ -934,6 +938,8 @@
handshake_confirmed: false,
+ ack_eliciting_sent: false,
+
closed: false,
grease: config.grease,
@@ -1386,6 +1392,8 @@
self.verified_peer_address = true;
}
+ self.ack_eliciting_sent = false;
+
Ok(read)
}
@@ -1882,6 +1890,23 @@
self.max_send_bytes = self.max_send_bytes.saturating_sub(written);
+ // (Re)start the idle timer if we are sending the first ACK-eliciting
+ // packet since last receiving a packet.
+ if ack_eliciting &&
+ !self.ack_eliciting_sent &&
+ self.local_transport_params.idle_timeout > 0
+ {
+ self.idle_timer = Some(
+ now + time::Duration::from_millis(
+ self.local_transport_params.idle_timeout,
+ ),
+ );
+ }
+
+ if ack_eliciting {
+ self.ack_eliciting_sent = true;
+ }
+
Ok(written)
}