From abe95d9c539c7c0a77f4b3cc546a667fed48f2a4 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Perennou Date: Fri, 14 Jul 2023 15:09:15 +0200 Subject: [PATCH] simplify channels cleanup logic Signed-off-by: Marc-Antoine Perennou --- src/channels.rs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/channels.rs b/src/channels.rs index bb46449e..a7194c7b 100644 --- a/src/channels.rs +++ b/src/channels.rs @@ -122,8 +122,8 @@ impl Channels { pub(crate) fn set_connection_closed(&self, error: Error) { self.connection_status.set_state(ConnectionState::Closed); - for (id, channel) in self.inner.lock().take_channels().drain() { - self.frames.clear_expected_replies(id, error.clone()); + for (id, channel) in self.inner.lock().channels.iter() { + self.frames.clear_expected_replies(*id, error.clone()); channel.set_closed(error.clone()); } } @@ -140,8 +140,8 @@ impl Channels { self.connection_status.set_state(ConnectionState::Error); self.frames.drop_pending(error.clone()); self.error_handler.on_error(error.clone()); - for (id, channel) in self.inner.lock().take_channels().drain() { - self.frames.clear_expected_replies(id, error.clone()); + for (id, channel) in self.inner.lock().channels.iter() { + self.frames.clear_expected_replies(*id, error.clone()); channel.set_connection_error(error.clone()); } } @@ -369,13 +369,4 @@ impl Inner { } Err(Error::ChannelsLimitReached) } - - fn take_channels(&mut self) -> HashMap { - let channel0 = self.channels.get(&0).cloned(); - let channels = std::mem::take(&mut self.channels); - if let Some(channel0) = channel0 { - self.channels.insert(0, channel0); - } - channels - } }