diff options
| author | kbleeke <[email protected]> | 2023-03-27 13:39:41 +0200 |
|---|---|---|
| committer | kbleeke <[email protected]> | 2023-03-27 13:39:41 +0200 |
| commit | 1c721cb20e44fdc7ec294792a9621d54361d344e (patch) | |
| tree | 4237bd1ec757a1792543ad498a51d7c2a50e1eb3 /src/control.rs | |
| parent | cde6f0f8628b50008df8cdeb52e80c186f63863a (diff) | |
cancel ioctl when future is dropped
Diffstat (limited to 'src/control.rs')
| -rw-r--r-- | src/control.rs | 23 |
1 files changed, 20 insertions, 3 deletions
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> { | |||
| 278 | } | 278 | } |
| 279 | 279 | ||
| 280 | async fn ioctl(&mut self, kind: IoctlType, cmd: u32, iface: u32, buf: &mut [u8]) -> usize { | 280 | async fn ioctl(&mut self, kind: IoctlType, cmd: u32, iface: u32, buf: &mut [u8]) -> usize { |
| 281 | // TODO cancel ioctl on future drop. | 281 | struct CancelOnDrop<'a>(&'a IoctlState); |
| 282 | |||
| 283 | impl CancelOnDrop<'_> { | ||
| 284 | fn defuse(self) { | ||
| 285 | core::mem::forget(self); | ||
| 286 | } | ||
| 287 | } | ||
| 288 | |||
| 289 | impl Drop for CancelOnDrop<'_> { | ||
| 290 | fn drop(&mut self) { | ||
| 291 | self.0.cancel_ioctl(); | ||
| 292 | } | ||
| 293 | } | ||
| 294 | |||
| 295 | let ioctl = CancelOnDrop(self.ioctl_state); | ||
| 296 | |||
| 297 | ioctl.0.do_ioctl(kind, cmd, iface, buf).await; | ||
| 298 | let resp_len = ioctl.0.wait_complete().await; | ||
| 299 | |||
| 300 | ioctl.defuse(); | ||
| 282 | 301 | ||
| 283 | self.ioctl_state.do_ioctl(kind, cmd, iface, buf).await; | ||
| 284 | let resp_len = self.ioctl_state.wait_complete().await; | ||
| 285 | resp_len | 302 | resp_len |
| 286 | } | 303 | } |
| 287 | } | 304 | } |
