Search code examples
c++infinite-loopwinusb

WinUsb_WritePipe goes into an infinite loop


I'm using the WinUsb_WritePipe function to write data on a USB Device.

The only trouble is that the function does an infinite loop.

//bulkOutPipe is a pipeId set precedently
//ucBuffer is an unsigned char array
//uiBytesToWrite corresponds to the size of the array
//ulBytesWritten is a unsigned long to stock the bytes written

std::cout << "Started writing" << std::endl;

WinUsb_WritePipe(devInfo->winUsbHandle, devInfo->bulkOutPipe, ucBuffer, uiBytesToWrite, &ulBytesWritten, 0);

//never gets here

This function used to return false but now it doesn't return anything.


Solution

  • To avoid an infinite loop, I would recommend always setting a timeout for I/O operations like this. You can use the WinUSB Functions for Pipe Policy Modification.