forked from lx/netapp
Add netapp function to drop all handlers
This commit is contained in:
parent
8a0bfa0ff6
commit
cfa64bc745
2 changed files with 11 additions and 2 deletions
|
@ -120,7 +120,7 @@ pub(crate) type DynEndpoint = Box<dyn GenericEndpoint + Send + Sync>;
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub(crate) trait GenericEndpoint {
|
pub(crate) trait GenericEndpoint {
|
||||||
async fn handle(&self, buf: &[u8], from: NodeID) -> Result<Vec<u8>, Error>;
|
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;
|
fn clone_endpoint(&self) -> DynEndpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_handler(&self) {
|
fn drop_handler(&self) {
|
||||||
self.0.handler.swap(None);
|
self.0.handler.swap(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -243,6 +243,15 @@ impl NetApp {
|
||||||
.log_err("Failed to await for connection collector");
|
.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.
|
/// 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.
|
/// The public key will be checked during the secret handshake process.
|
||||||
/// This function returns once the connection has been established and a
|
/// This function returns once the connection has been established and a
|
||||||
|
|
Loading…
Reference in a new issue