@@ -363,6 +363,31 @@ int libusb_control_transfer(libusb_device_handle* dev_handle, uint8_t bmRequestT
363363 return (bytes_transferred);
364364}
365365
366+ int libusb_bulk_transfer (libusb_device_handle* dev_handle, uint8_t endpoint, uint8_t *data, int length, int *transferred, unsigned int timeout)
367+ {
368+ // in libusb-1.0 a timeout of zero it means 'wait indefinitely'; in libusb-0.1, a timeout of zero means 'return immediately'!
369+ timeout = (0 == timeout) ? 60000 : timeout; // wait 60000ms (60s = 1min) if the transfer is supposed to wait indefinitely...
370+ int bytes_transferred;
371+ if (endpoint & LIBUSB_ENDPOINT_IN) { // Device to Host
372+ bytes_transferred = usb_bulk_read (dev_handle->handle , endpoint, (char *)data, length, timeout);
373+ } else { // Host to Device
374+ bytes_transferred = usb_bulk_write (dev_handle->handle , endpoint, (char *)data, length, timeout);
375+ }
376+ if (bytes_transferred < 0 ) {
377+ // 0 on success (and populates transferred)
378+ // LIBUSB_ERROR_TIMEOUT if the transfer timed out (and populates transferred)
379+ // LIBUSB_ERROR_PIPE if the endpoint halted
380+ // LIBUSB_ERROR_OVERFLOW if the device offered more data, see Packets and overflows
381+ // LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
382+ // another LIBUSB_ERROR code on other failures
383+ *transferred = 0 ;
384+ LIBUSBEMU_ERROR_LIBUSBWIN32 ();
385+ return (LIBUSB_ERROR_OTHER);
386+ }
387+ *transferred = bytes_transferred;
388+ return 0 ;
389+ }
390+
366391// FROM HERE ON CODE BECOMES QUITE MESSY: ASYNCHRONOUS TRANSFERS MANAGEMENT
367392
368393struct libusb_transfer * libusb_alloc_transfer (int iso_packets)
0 commit comments