From 2adc1bc3cc89454b5a3052201baf287c6d574999 Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Tue, 23 Feb 2021 21:28:43 -0800 Subject: [PATCH] Remove unnecessary send stream state --- quinn-proto/src/connection/streams.rs | 4 ++-- quinn-proto/src/connection/streams/send.rs | 19 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/quinn-proto/src/connection/streams.rs b/quinn-proto/src/connection/streams.rs index ac01113f0..12b91b254 100644 --- a/quinn-proto/src/connection/streams.rs +++ b/quinn-proto/src/connection/streams.rs @@ -715,8 +715,8 @@ impl Streams { } let id = frame.id; self.unacked_data -= frame.offsets.end - frame.offsets.start; - stream.ack(frame); - if stream.state != SendState::DataRecvd { + if !stream.ack(frame) { + // The stream is unfinished or may still need retransmits return; } diff --git a/quinn-proto/src/connection/streams/send.rs b/quinn-proto/src/connection/streams/send.rs index a33a69c70..79137bccd 100644 --- a/quinn-proto/src/connection/streams/send.rs +++ b/quinn-proto/src/connection/streams/send.rs @@ -79,16 +79,17 @@ impl Send { self.stop_reason = Some(error_code); } - pub(super) fn ack(&mut self, frame: frame::StreamMeta) { + /// Returns whether the stream has been finished and all data has been acknowledged by the peer + pub(super) fn ack(&mut self, frame: frame::StreamMeta) -> bool { self.pending.ack(frame.offsets); - if let SendState::DataSent { - ref mut finish_acked, - } = self.state - { - *finish_acked |= frame.fin; - if *finish_acked && self.pending.is_fully_acked() { - self.state = SendState::DataRecvd; + match self.state { + SendState::DataSent { + ref mut finish_acked, + } => { + *finish_acked |= frame.fin; + *finish_acked && self.pending.is_fully_acked() } + _ => false, } } @@ -157,8 +158,6 @@ pub(super) enum SendState { DataSent { finish_acked: bool }, /// Sent RESET ResetSent, - /// All sent data acknowledged - DataRecvd, } /// Reasons why attempting to finish a stream might fail