Add netapp function to drop all handlers
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Alex 2021-10-14 17:33:12 +02:00
parent 8a0bfa0ff6
commit cfa64bc745
No known key found for this signature in database
GPG Key ID: EDABF9711E244EB1
2 changed files with 11 additions and 2 deletions

View File

@ -120,7 +120,7 @@ pub(crate) type DynEndpoint = Box<dyn GenericEndpoint + Send + Sync>;
#[async_trait]
pub(crate) trait GenericEndpoint {
async fn handle(&self, buf: &[u8], from: NodeID) -> Result<Vec<u8>, 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);
}

View File

@ -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