libusb_bulk_transfer Function Description
-
API_EXPORTED int libusb_bulk_transfer(struct libusb_device_handle *dev_handle,
-
unsigned char endpoint, unsigned char *data, int length, int *transferred,
-
unsigned int timeout)
-
{
-
// Call do_sync_bulk_transfer
-
return do_sync_bulk_transfer(dev_handle, endpoint, data, length,
-
transferred, timeout, LIBUSB_TRANSFER_TYPE_BULK);
-
}
Code:
-
static int do_sync_bulk_transfer(struct libusb_device_handle *dev_handle,
-
unsigned char endpoint, unsigned char *buffer, int length,
-
int *transferred, unsigned int timeout, unsigned char type)
-
{
-
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
-
int completed = 0;
-
int r;
-
-
if (!transfer)
-
return LIBUSB_ERROR_NO_MEM;
-
-
// transmission structure must have its core is the data transmission as well as some of the state is actually a truck
-
libusb_fill_bulk_transfer(transfer, dev_handle, endpoint, buffer, length,
-
bulk_transfer_cb, &completed, timeout);
-
transfer->type = type;
-
-
// in Bahrain truck cargo can be set off, apply for transfer
-
r = libusb_submit_transfer(transfer);
-
if (r < 0) {
-
libusb_free_transfer(transfer);
-
return r;
-
}
-
-
-
-
// complete is the completion of the loading of a standard
-
-
while (!completed) {
-
r = libusb_handle_events(HANDLE_CTX(dev_handle));
-
if (r < 0) {
-
if (r == LIBUSB_ERROR_INTERRUPTED)
-
continue;
-
libusb_cancel_transfer(transfer);
-
while (!completed)
-
if (libusb_handle_events(HANDLE_CTX(dev_handle)) < 0)
-
break;
-
libusb_free_transfer(transfer);
-
return r;
-
}
-
}
-
-
*transferred = transfer->actual_length;
-
switch (transfer->status) {
-
case LIBUSB_TRANSFER_COMPLETED:
-
r = 0;
-
break;
-
case LIBUSB_TRANSFER_TIMED_OUT:
-
r = LIBUSB_ERROR_TIMEOUT;
-
break;
-
case LIBUSB_TRANSFER_STALL:
-
r = LIBUSB_ERROR_PIPE;
-
break;
-
case LIBUSB_TRANSFER_OVERFLOW:
-
r = LIBUSB_ERROR_OVERFLOW;
-
break;
-
case LIBUSB_TRANSFER_NO_DEVICE:
-
r = LIBUSB_ERROR_NO_DEVICE;
-
break;
-
default:
-
usbi_warn(HANDLE_CTX(dev_handle),
-
"unrecognised status code %d", transfer->status);
-
r = LIBUSB_ERROR_OTHER;
-
}
-
libusb_free_transfer(transfer);
-
return r;
-
}https://blog.csdn.net/zdyueguanyun/article/details/51192885