Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special-case sync return from async call and preserve last error #55

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tormodvolden
Copy link
Contributor

These are a few things I noticed while reviewing the libusb0 backend code. They are not tested and do not fix any reported issues, but I believe they make the code more correct and will give better error diagnosis.

usb_control_msg() returns various error codes, so map these to
Win32 errors that can be read out by calling functions.

Signed-off-by: Tormod Volden <[email protected]>
If DeviceIoControl() succeeds synchronously it isn't advised to call
GetOverlappedResult() [1].

In practive it seems like GetOverlappedResult() works in any case, but
all Microsoft examples treat the synchronous completion case separately.

Also preserve the Win32 last error from the failing call since a failing
CloseHandle() might clobber it.

[1] https://learn.microsoft.com/en-GB/troubleshoot/windows/win32/asynchronous-disk-io-synchronous

Signed-off-by: Tormod Volden <[email protected]>
@mcuee mcuee added the libusb0.sys specific to libusb0.sys backend of libusbk.dll label Oct 8, 2023
@mcuee
Copy link
Owner

mcuee commented Oct 20, 2023

@TravisRo

Hi Travis, I think this PR is safe to merge. Please review when you got the time. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libusb0.sys specific to libusb0.sys backend of libusbk.dll
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants