修复control_io返回值
This commit is contained in:
parent
e4507f0ed6
commit
0343eecad1
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue