Skip to content

Commit

Permalink
Merge pull request #152 from YgorSouza/windows-cancel-io-ex
Browse files Browse the repository at this point in the history
Use CancelIoEx instead of CancelIo on windows_native
  • Loading branch information
ruabmbua authored Mar 2, 2024
2 parents c2b41a5 + 884544d commit f37a860
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/windows_native/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use windows_sys::Win32::Storage::FileSystem::{
OPEN_EXISTING,
};
use windows_sys::Win32::System::Threading::ResetEvent;
use windows_sys::Win32::System::IO::{CancelIo, DeviceIoControl};
use windows_sys::Win32::System::IO::{CancelIoEx, DeviceIoControl};

const STRING_BUF_LEN: usize = 128;

Expand Down Expand Up @@ -179,7 +179,7 @@ impl HidDeviceBackendBase for HidDevice {
if res != TRUE {
let err = Win32Error::last();
if err != Win32Error::IoPending {
unsafe { CancelIo(self.device_handle.as_raw()) };
unsafe { CancelIoEx(self.device_handle.as_raw(), state.overlapped.as_raw()) };
self.read_pending.set(false);
return Err(err.into());
}
Expand Down Expand Up @@ -335,7 +335,16 @@ impl HidDeviceBackendWindows for HidDevice {
impl Drop for HidDevice {
fn drop(&mut self) {
unsafe {
CancelIo(self.device_handle.as_raw());
for state in [
&mut self.read_state,
&mut self.write_state,
&mut self.feature_state,
] {
let mut state = state.borrow_mut();
if CancelIoEx(self.device_handle.as_raw(), state.overlapped.as_raw()) > 0 {
_ = state.overlapped.get_result(&self.device_handle, None);
}
}
}
}
}
Expand Down

0 comments on commit f37a860

Please sign in to comment.