From 0343eecad1eb1bd4bc1d58cab59b7c03c246ab54 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Thu, 21 Jul 2022 17:55:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcontrol=5Fio=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- device/win_usb/win_usb.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/device/win_usb/win_usb.cpp b/device/win_usb/win_usb.cpp index 64bd069..1ca776e 100644 --- a/device/win_usb/win_usb.cpp +++ b/device/win_usb/win_usb.cpp @@ -757,13 +757,31 @@ int usb_device::transfer_control(uint8_t type, uint8_t req, uint16_t val, uint16 irp.uLength = len; irp.uOffset = val; if (DeviceIoControl((HANDLE)handle_, IOCTL_SEND_USB_REQUEST, &irp, sizeof(irp), data, len, oc->io_bytes(), oc->over_lapped())) - ret = *oc->io_bytes(); + { + if (irp.fTransferDirectionIn) + { + GetOverlappedResult((HANDLE)handle_, oc->over_lapped(), oc->io_bytes(), FALSE); + ret = *oc->io_bytes(); + } + else + { + ret = len; + } + } else if (GetLastError() == ERROR_IO_PENDING) { ret = WaitForSingleObject(oc->over_lapped()->hEvent, timeout) == WAIT_TIMEOUT ? LIBUSB_ERROR_TIMEOUT : *oc->io_bytes(); } else - ret = LIBUSB_ERROR_PIPE; + { + io = GetLastError(); + if (io == ERROR_ACCESS_DENIED) + ret = LIBUSB_ERROR_ACCESS; + else if (io == ERROR_SEM_TIMEOUT) + ret = LIBUSB_ERROR_TIMEOUT; + else + ret = LIBUSB_ERROR_PIPE; + } oc->release(); }