Skip to content

Commit

Permalink
Make Endpoint::close not owning
Browse files Browse the repository at this point in the history
  • Loading branch information
iacore committed Nov 4, 2024
1 parent ab3afef commit 8cb16fc
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions iroh-net/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,20 +847,18 @@ impl Endpoint {
///
/// Returns an error if closing the magic socket failed.
/// TODO: Document error cases.
pub async fn close(self, error_code: VarInt, reason: &[u8]) -> Result<()> {
pub async fn close(&self, error_code: VarInt, reason: &[u8]) -> Result<()> {
let Endpoint {
msock,
endpoint,
cancel_token,
..
} = self;
} = &self;
cancel_token.cancel();
tracing::debug!("Closing connections");
endpoint.close(error_code, reason);
endpoint.wait_idle().await;
// In case this is the last clone of `Endpoint`, dropping the `quinn::Endpoint` will
// make it more likely that the underlying socket is not polled by quinn anymore after this
drop(endpoint);

tracing::debug!("Connections closed");

msock.close().await?;
Expand Down

0 comments on commit 8cb16fc

Please sign in to comment.