Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erkki-silvola committed Feb 10, 2025
1 parent 32714af commit 66530af
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/platform/windows_winusb/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,16 @@ impl BitSet256 {
}
}

struct SendWinUSBHandle(WINUSB_INTERFACE_HANDLE);

unsafe impl Send for SendWinUSBHandle {}
unsafe impl Sync for SendWinUSBHandle {}

/// A file handle and the WinUSB handle for the first interface.
pub(crate) struct WinusbFileHandle {
first_interface: u8,
handle: OwnedHandle,
winusb_handle: WINUSB_INTERFACE_HANDLE,
winusb_handle: SendWinUSBHandle,
claimed_interfaces: BitSet256,
}

Expand All @@ -229,13 +234,13 @@ impl WinusbFileHandle {
let handle = create_file(&path)?;
super::events::register(&handle)?;

let winusb_handle = unsafe {
let winusb_handle: SendWinUSBHandle = unsafe {
let mut h = std::ptr::null_mut();
if WinUsb_Initialize(raw_handle(&handle), &mut h) == FALSE {
error!("WinUsb_Initialize failed: {:?}", io::Error::last_os_error());
return Err(io::Error::last_os_error());
}
h
SendWinUSBHandle(h)
};

debug!("Opened WinUSB handle for {path} (interface {first_interface})");
Expand All @@ -262,13 +267,14 @@ impl WinusbFileHandle {
));
}

let winusb_handle = if self.first_interface == interface_number {
self.winusb_handle
let winusb_handle: WINUSB_INTERFACE_HANDLE = if self.first_interface == interface_number {
self.winusb_handle.0
} else {
unsafe {
let mut out_handle = std::ptr::null_mut();
let idx = interface_number - self.first_interface - 1;
if WinUsb_GetAssociatedInterface(self.winusb_handle, idx, &mut out_handle) == FALSE
if WinUsb_GetAssociatedInterface(self.winusb_handle.0, idx, &mut out_handle)
== FALSE
{
error!(
"WinUsb_GetAssociatedInterface for {} on {} failed: {:?}",
Expand Down Expand Up @@ -306,7 +312,7 @@ impl Drop for WinusbFileHandle {
self.first_interface
);
unsafe {
WinUsb_Free(self.winusb_handle);
WinUsb_Free(self.winusb_handle.0);
}
}
}
Expand Down

0 comments on commit 66530af

Please sign in to comment.