I worked on the synchronous libusb in my Qt project with good results and now I need the asynchronous features of this library. I understood reading here, here and here that, after I've registered my callback function using the libusb_fill_control_transfer
and submitted a transfer with libusb_submit_transfer
, I need to "keep live" the libusb_handle_events_completed
inside a while loop to get the transfer related events since the libusb doesn't have its own thread. for example you can read a code like this
libusb_fill_control_transfer(transfer, dev, buffer, cb, &completed, 1000);
libusb_submit_transfer(transfer);
while (!completed) {
libusb_handle_events_completed(ctx, &completed);
}
Now if I want read a packet that I don't know when it occurs, I think that goes against the asynchronous nature submit a read and wait in the while with libusb_handle_events_completed
until the event is triggered.
Then, do I need to create a separate thread within the libusb_handle_events_completed
in an infinite while loop?
Can anyone, with experience in the asynchronous features of libusb library, give some suggestions on the right approach to handle the transfer events?
question from:
https://stackoverflow.com/questions/65853834/how-to-properly-use-the-asynchronous-libusb 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…