diff --git a/src/lib.rs b/src/lib.rs index 7a5ce7e..eb01e94 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,7 +83,7 @@ impl IpStackConfig { pub struct IpStack { accept_receiver: UnboundedReceiver, - _handle: JoinHandle>, // Just hold the task handle + handle: JoinHandle>, } impl IpStack { @@ -94,7 +94,7 @@ impl IpStack { let (accept_sender, accept_receiver) = mpsc::unbounded_channel::(); IpStack { accept_receiver, - _handle: run(config, device, accept_sender), + handle: run(config, device, accept_sender), } } @@ -103,6 +103,12 @@ impl IpStack { } } +impl Drop for IpStack { + fn drop(&mut self) { + self.handle.abort(); + } +} + fn run( config: IpStackConfig, mut device: Device,