From 1c721cb20e44fdc7ec294792a9621d54361d344e Mon Sep 17 00:00:00 2001 From: kbleeke Date: Mon, 27 Mar 2023 13:39:41 +0200 Subject: cancel ioctl when future is dropped --- src/control.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/control.rs') diff --git a/src/control.rs b/src/control.rs index 0dbf6d44f..30d5d0924 100644 --- a/src/control.rs +++ b/src/control.rs @@ -278,10 +278,27 @@ impl<'a> Control<'a> { } async fn ioctl(&mut self, kind: IoctlType, cmd: u32, iface: u32, buf: &mut [u8]) -> usize { - // TODO cancel ioctl on future drop. + struct CancelOnDrop<'a>(&'a IoctlState); + + impl CancelOnDrop<'_> { + fn defuse(self) { + core::mem::forget(self); + } + } + + impl Drop for CancelOnDrop<'_> { + fn drop(&mut self) { + self.0.cancel_ioctl(); + } + } + + let ioctl = CancelOnDrop(self.ioctl_state); + + ioctl.0.do_ioctl(kind, cmd, iface, buf).await; + let resp_len = ioctl.0.wait_complete().await; + + ioctl.defuse(); - self.ioctl_state.do_ioctl(kind, cmd, iface, buf).await; - let resp_len = self.ioctl_state.wait_complete().await; resp_len } } -- cgit