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

quinn: introduce waking helpers #1908

Merged
merged 2 commits into from
Jun 23, 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
48 changes: 18 additions & 30 deletions quinn/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,11 +1061,7 @@ impl State {
ConnectionLost { reason } => {
self.terminate(reason, shared);
}
Stream(StreamEvent::Writable { id }) => {
if let Some(writer) = self.blocked_writers.remove(&id) {
writer.wake();
}
}
Stream(StreamEvent::Writable { id }) => wake_stream(id, &mut self.blocked_writers),
Stream(StreamEvent::Opened { dir: Dir::Uni }) => {
shared.stream_incoming[Dir::Uni as usize].notify_waiters();
}
Expand All @@ -1078,27 +1074,15 @@ impl State {
DatagramsUnblocked => {
shared.datagrams_unblocked.notify_waiters();
}
Stream(StreamEvent::Readable { id }) => {
if let Some(reader) = self.blocked_readers.remove(&id) {
reader.wake();
}
}
Stream(StreamEvent::Readable { id }) => wake_stream(id, &mut self.blocked_readers),
Stream(StreamEvent::Available { dir }) => {
// Might mean any number of streams are ready, so we wake up everyone
shared.stream_budget_available[dir as usize].notify_waiters();
}
Stream(StreamEvent::Finished { id }) => {
if let Some(stopped) = self.stopped.remove(&id) {
stopped.wake();
}
}
Stream(StreamEvent::Finished { id }) => wake_stream(id, &mut self.stopped),
Stream(StreamEvent::Stopped { id, .. }) => {
if let Some(stopped) = self.stopped.remove(&id) {
stopped.wake();
}
if let Some(writer) = self.blocked_writers.remove(&id) {
writer.wake();
}
wake_stream(id, &mut self.stopped);
wake_stream(id, &mut self.blocked_writers);
}
}
}
Expand Down Expand Up @@ -1167,12 +1151,8 @@ impl State {
if let Some(x) = self.on_handshake_data.take() {
let _ = x.send(());
}
for (_, writer) in self.blocked_writers.drain() {
writer.wake()
}
for (_, reader) in self.blocked_readers.drain() {
reader.wake()
}
wake_all(&mut self.blocked_writers);
wake_all(&mut self.blocked_readers);
shared.stream_budget_available[Dir::Uni as usize].notify_waiters();
shared.stream_budget_available[Dir::Bi as usize].notify_waiters();
shared.stream_incoming[Dir::Uni as usize].notify_waiters();
Expand All @@ -1182,9 +1162,7 @@ impl State {
if let Some(x) = self.on_connected.take() {
let _ = x.send(false);
}
for (_, waker) in self.stopped.drain() {
waker.wake();
}
wake_all(&mut self.stopped);
shared.closed.notify_waiters();
}

Expand Down Expand Up @@ -1228,6 +1206,16 @@ impl fmt::Debug for State {
}
}

fn wake_stream(stream_id: StreamId, wakers: &mut FxHashMap<StreamId, Waker>) {
if let Some(waker) = wakers.remove(&stream_id) {
waker.wake();
}
}

fn wake_all(wakers: &mut FxHashMap<StreamId, Waker>) {
wakers.drain().for_each(|(_, waker)| waker.wake())
}

/// Errors that can arise when sending a datagram
#[derive(Debug, Error, Clone, Eq, PartialEq)]
pub enum SendDatagramError {
Expand Down