diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-03-27 11:45:35 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-03-27 11:45:35 +0000 |
| commit | 07fe37b5ee5d5643eca4bc8db13d8bed5399cefa (patch) | |
| tree | 4237bd1ec757a1792543ad498a51d7c2a50e1eb3 /src | |
| parent | cde6f0f8628b50008df8cdeb52e80c186f63863a (diff) | |
| parent | 1c721cb20e44fdc7ec294792a9621d54361d344e (diff) | |
Merge pull request #52 from kbleeke/cancel-ioctl
cancel ioctl when future is dropped
Diffstat (limited to 'src')
| -rw-r--r-- | src/control.rs | 23 | ||||
| -rw-r--r-- | src/ioctl.rs | 4 |
2 files changed, 24 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 | } |
diff --git a/src/ioctl.rs b/src/ioctl.rs index 6a7465593..f5ab410db 100644 --- a/src/ioctl.rs +++ b/src/ioctl.rs | |||
| @@ -88,6 +88,10 @@ impl IoctlState { | |||
| 88 | pending | 88 | pending |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | pub fn cancel_ioctl(&self) { | ||
| 92 | self.state.set(IoctlStateInner::Done { resp_len: 0 }); | ||
| 93 | } | ||
| 94 | |||
| 91 | pub async fn do_ioctl(&self, kind: IoctlType, cmd: u32, iface: u32, buf: &mut [u8]) -> usize { | 95 | pub async fn do_ioctl(&self, kind: IoctlType, cmd: u32, iface: u32, buf: &mut [u8]) -> usize { |
| 92 | warn!("doing ioctl"); | 96 | warn!("doing ioctl"); |
| 93 | self.state | 97 | self.state |
