Windows: Allow synchronous control transfers (for libusb0)
authorTormod Volden <debian.tormod@gmail.com>
Thu, 28 Oct 2021 12:48:55 +0000 (14:48 +0200)
committerTormod Volden <debian.tormod@gmail.com>
Tue, 9 Nov 2021 08:19:59 +0000 (09:19 +0100)
Some of the changes in commit 9c28ad2 rely on all transfers having (or
appearing to have) asynchronous completion.

However, the libusb0.sys backend of libusbk.dll performs all control
transfers synchronously and ignores any "overlapped" structure handed to
it. Our asynchronous handling will in this case be pending and
eventually time out although the USB request itself was successful.

Therefore restore the possibility of synchronous completion of control
transfers, by forcing the completion handling on a successful return
from request submission. This brings the code closer to how it was
established in commit ce95f65.

Fixes #94

Tested-by: Xiaofan Chen <xiaofanc@gmail.com>
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
libusb/os/windows_winusb.c
libusb/version_nano.h

index df17d81..a03d6a5 100644 (file)
@@ -2766,7 +2766,7 @@ static int winusbx_submit_control_transfer(int sub_api, struct usbi_transfer *it
        struct winusb_transfer_priv *transfer_priv = get_winusb_transfer_priv(itransfer);
        struct winusb_device_handle_priv *handle_priv = get_winusb_device_handle_priv(transfer->dev_handle);
        PWINUSB_SETUP_PACKET setup = (PWINUSB_SETUP_PACKET)transfer->buffer;
-       ULONG size;
+       ULONG size, transferred;
        HANDLE winusb_handle;
        OVERLAPPED *overlapped;
        int current_interface;
@@ -2806,11 +2806,13 @@ static int winusbx_submit_control_transfer(int sub_api, struct usbi_transfer *it
                }
                windows_force_sync_completion(itransfer, 0);
        } else {
-               if (!WinUSBX[sub_api].ControlTransfer(winusb_handle, *setup, transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE, size, NULL, overlapped)) {
+               if (!WinUSBX[sub_api].ControlTransfer(winusb_handle, *setup, transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE, size, &transferred, overlapped)) {
                        if (GetLastError() != ERROR_IO_PENDING) {
                                usbi_warn(TRANSFER_CTX(transfer), "ControlTransfer failed: %s", windows_error_str(0));
                                return LIBUSB_ERROR_IO;
                        }
+               } else {
+                       windows_force_sync_completion(itransfer, transferred);
                }
        }
 
index 838c0a6..09d6e2e 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11673
+#define LIBUSB_NANO 11674