Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use retain to clear out old streams #2144

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 5 additions & 18 deletions neqo-transport/src/recv_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,19 @@ impl RecvStreams {
}

pub fn clear_terminal(&mut self, send_streams: &SendStreams, role: Role) -> (u64, u64) {
let recv_to_remove = self
.streams
.iter()
.filter_map(|(id, stream)| {
// Remove all streams for which the receiving is done (or aborted).
// But only if they are unidirectional, or we have finished sending.
if stream.is_terminal() && (id.is_uni() || !send_streams.exists(*id)) {
Some(*id)
} else {
None
}
})
.collect::<Vec<_>>();

let mut removed_bidi = 0;
let mut removed_uni = 0;
for id in &recv_to_remove {
self.streams.remove(id);
if id.is_remote_initiated(role) {
self.streams.retain(|id, s| {
let dead = s.is_terminal() && (id.is_uni() || !send_streams.exists(*id));
if dead && id.is_remote_initiated(role) {
if id.is_bidi() {
removed_bidi += 1;
} else {
removed_uni += 1;
}
}
}
!dead
});

(removed_bidi, removed_uni)
}
Expand Down
Loading