From a9b8b0224da0f6904e5e7b19666ead3e5ce65a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Mon, 1 Nov 2021 02:17:49 +0100 Subject: [PATCH] aquatic_http: glommio: remove closed connections in own fn --- aquatic_http/src/lib/network.rs | 42 ++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/aquatic_http/src/lib/network.rs b/aquatic_http/src/lib/network.rs index d26febe..f173cd7 100644 --- a/aquatic_http/src/lib/network.rs +++ b/aquatic_http/src/lib/network.rs @@ -89,22 +89,11 @@ pub async fn run_socket_worker( // Periodically remove closed connections TimerActionRepeat::repeat( enclose!((config, connection_slab, connections_to_remove) move || { - enclose!((config, connection_slab, connections_to_remove) move || async move { - let connections_to_remove = connections_to_remove.replace(Vec::new()); - - for connection_id in connections_to_remove { - if let Some(_) = connection_slab.borrow_mut().try_remove(connection_id) { - ::log::debug!("removed connection with id {}", connection_id); - } else { - ::log::error!( - "couldn't remove connection with id {}, it is not in connection slab", - connection_id - ); - } - } - - Some(Duration::from_secs(config.cleaning.interval)) - })() + remove_closed_connections( + config.clone(), + connection_slab.clone(), + connections_to_remove.clone(), + ) }), ); @@ -151,6 +140,27 @@ pub async fn run_socket_worker( } } +async fn remove_closed_connections( + config: Rc, + connection_slab: Rc>>, + connections_to_remove: Rc>>, +) -> Option { + let connections_to_remove = connections_to_remove.replace(Vec::new()); + + for connection_id in connections_to_remove { + if let Some(_) = connection_slab.borrow_mut().try_remove(connection_id) { + ::log::debug!("removed connection with id {}", connection_id); + } else { + ::log::error!( + "couldn't remove connection with id {}, it is not in connection slab", + connection_id + ); + } + } + + Some(Duration::from_secs(config.cleaning.interval)) +} + async fn receive_responses( mut response_receiver: ConnectedReceiver, connection_references: Rc>>,