Skip to content

Commit

Permalink
IoLoop: rewrite should_continue condition
Browse files Browse the repository at this point in the history
This makes it way more readable.
Also, we now make sure that we properly continue writing to the TCP
stream if w have pending writes and it's not in error.
This enables us not to leave promises behind and properly answering to a
rabbitmq server's connection.close with a connection.close-ok.

Fixes #413

Properly fixes #409

Signed-off-by: Marc-Antoine Perennou <[email protected]>
  • Loading branch information
Keruspe committed Jul 27, 2024
1 parent e480f23 commit 73e6abe
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/io_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,15 @@ impl IoLoop {
}

fn should_continue(&self) -> bool {
(self.status != Status::Connected
|| self.connection_status.connected()
|| self.connection_status.closing())
&& self.status != Status::Stop
&& !self.connection_status.errored()
match self.status {
Status::Initial => !self.connection_status.errored(),
Status::Stop => false,
Status::Connected => {
self.connection_status.connected()
|| self.connection_status.closing()
|| !self.serialized_frames.is_empty()
}
}
}

pub fn start(mut self) -> Result<()> {
Expand Down Expand Up @@ -259,6 +263,7 @@ impl IoLoop {
fn clear_serialized_frames(&mut self, error: Error) {
for (_, resolver) in std::mem::take(&mut self.serialized_frames) {
if let Some(resolver) = resolver {
trace!("We're quitting but had leftover frames, tag them as 'not sent' with current error");
resolver.reject(error.clone());
}
}
Expand Down

0 comments on commit 73e6abe

Please sign in to comment.