From cfa64bc745969cfc3684a70b45d71128f8335460 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 14 Oct 2021 17:33:12 +0200 Subject: [PATCH] Add netapp function to drop all handlers --- src/endpoint.rs | 4 ++-- src/netapp.rs | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/endpoint.rs b/src/endpoint.rs index 77d7468..f30b25e 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -120,7 +120,7 @@ pub(crate) type DynEndpoint = Box; #[async_trait] pub(crate) trait GenericEndpoint { async fn handle(&self, buf: &[u8], from: NodeID) -> Result, Error>; - fn clear_handler(&self); + fn drop_handler(&self); fn clone_endpoint(&self) -> DynEndpoint; } @@ -148,7 +148,7 @@ where } } - fn clear_handler(&self) { + fn drop_handler(&self) { self.0.handler.swap(None); } diff --git a/src/netapp.rs b/src/netapp.rs index a7a3acf..8c0b50c 100644 --- a/src/netapp.rs +++ b/src/netapp.rs @@ -243,6 +243,15 @@ impl NetApp { .log_err("Failed to await for connection collector"); } + /// Drop all endpoint handlers + /// + /// Use this when terminating to break reference cycles + pub fn drop_all_handlers(&self) { + for (_, endpoint) in self.endpoints.read().unwrap().iter() { + endpoint.drop_handler(); + } + } + /// Attempt to connect to a peer, given by its ip:port and its public key. /// The public key will be checked during the secret handshake process. /// This function returns once the connection has been established and a