修复control_io返回值

This commit is contained in:
gb 2022-07-21 17:55:25 +08:00
parent e4507f0ed6
commit 0343eecad1
1 changed files with 20 additions and 2 deletions

View File

@ -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()))
{
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
{
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();
}