cancel ioctl when future is dropped
This commit is contained in:
parent
cde6f0f862
commit
1c721cb20e
2 changed files with 24 additions and 3 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue