Merge pull request #52 from kbleeke/cancel-ioctl

cancel ioctl when future is dropped
This commit is contained in:
Dario Nieuwenhuis 2023-03-27 11:45:35 +00:00 committed by GitHub
commit 07fe37b5ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View File

@ -278,10 +278,27 @@ impl<'a> Control<'a> {
} }
async fn ioctl(&mut self, kind: IoctlType, cmd: u32, iface: u32, buf: &mut [u8]) -> usize { 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 resp_len
} }
} }

View File

@ -88,6 +88,10 @@ impl IoctlState {
pending pending
} }
pub fn cancel_ioctl(&self) {
self.state.set(IoctlStateInner::Done { resp_len: 0 });
}
pub async fn do_ioctl(&self, kind: IoctlType, cmd: u32, iface: u32, buf: &mut [u8]) -> usize { pub async fn do_ioctl(&self, kind: IoctlType, cmd: u32, iface: u32, buf: &mut [u8]) -> usize {
warn!("doing ioctl"); warn!("doing ioctl");
self.state self.state