Skip to content

Commit

Permalink
Factor out criterion for sending stream-level flow control
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed May 22, 2024
1 parent 7dfd5e4 commit 91dd240
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions quinn-proto/src/connection/streams/recv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ impl Recv {
// smaller than `stream_receive_window` in order to make sure the stream
// does not get stuck.
let diff = max_stream_data - self.sent_max_stream_data;
let transmit =
self.final_offset_unknown() && !self.stopped && diff >= (stream_receive_window / 8);
let transmit = self.can_send_flow_control() && diff >= (stream_receive_window / 8);
(max_stream_data, ShouldTransmit(transmit))
}

Expand All @@ -134,6 +133,13 @@ impl Recv {
matches!(self.state, RecvState::Recv { size: None })
}

/// Whether stream-level flow control updates should be sent for this stream
pub(super) fn can_send_flow_control(&self) -> bool {
// Stream-level flow control is redundant if the sender has already sent the whole stream,
// and moot if we no longer want data on this stream.
self.final_offset_unknown() && !self.stopped
}

/// Whether data is still being accepted from the peer
pub(super) fn is_receiving(&self) -> bool {
matches!(self.state, RecvState::Recv { .. })
Expand Down
4 changes: 2 additions & 2 deletions quinn-proto/src/connection/streams/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl StreamsState {
self.recv
.get(&id)
.and_then(|s| s.as_ref())
.map_or(false, |s| s.final_offset_unknown() && !s.stopped)
.map_or(false, |s| s.can_send_flow_control())
}

pub(in crate::connection) fn write_control_frames(
Expand Down Expand Up @@ -446,7 +446,7 @@ impl StreamsState {
Some(x) => x,
None => continue,
};
if !rs.final_offset_unknown() || rs.stopped {
if !rs.can_send_flow_control() {
continue;
}
retransmits.get_or_create().max_stream_data.insert(id);
Expand Down

0 comments on commit 91dd240

Please sign in to comment.