The official documentation for the libusb-win32 library makes no mention of the asynchronous API that the library provides. Evidence of these functions is to be found in the prototypes defined in the header file usb.h that forms part of the source code for the win32 port of this important library.
Those async functions are defined as follows:
int usb_submit_async(void *context, char *bytes, int size);
int usb_reap_async(void *context, int timeout);
int usb_reap_async_nocancel(void *context, int timeout);
int usb_cancel_async(void *context);
int usb_free_async(void **context);
What still remains absent in the async API is any documentation on how to use it!
The clearest example of working async code that I have found was written by Kevin Kofler. Kevin developed it as part of the USB codebase for the Texas Instrument calculator project. Here is a small excerpt of Kevin’s code. It should get you going with async USB transfers in Windows using libusb-win32:
[..]
/* variables for slv_check and slv_bulk_read2 */
static int io_pending = 0;
uint8_t rBuf[64];
uint8_t* rBufPtr;
[..]
static int slv_check(CableHandle *h, int *status) {
int ret;
if (!io_pending) {
ret = usb_bulk_setup_async(uHdl, &context, TIGL_BULK_IN);
if (ret < 0)
return ERR_READ_ERROR;
ret = usb_submit_async(context, (char*)rBuf, max_ps);
if (ret < 0) {
usb_free_async(&context);
return ERR_READ_ERROR;
}
io_pending = TRUE;
}
ret = usb_reap_async_nocancel(context, 0);
if (ret < 0 && ret != -ETIMEDOUT) { // Error, unlink URB and return failure.
usb_cancel_async(context);
usb_free_async(&context);
io_pending = FALSE;
if (ret > 0) {
nBytesRead = ret;
rBufPtr = rBuf;
*status = STATUS_RX; // data available
}
}
return 0;
}









