Merge pull request #52 from kbleeke/cancel-ioctl
cancel ioctl when future is dropped
This commit is contained in:
commit
07fe37b5ee
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -88,6 +88,10 @@ impl IoctlState {
|
||||
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 {
|
||||
warn!("doing ioctl");
|
||||
self.state
|
||||
|
Loading…
Reference in New Issue
Block a user