Ticket #123 (assigned defect)
libusb_handle_events_timeout() only handles one event
|Reported by:||egnor||Owned by:||hjelmn|
It's possible I misunderstand the desired behavior, but:
"If a zero timeval is passed, this function will handle any already-pending events and then immediately return in non-blocking style."
The question is whether it will handle _all_ work that needs to be done at that point. The quote above seems to indicate that it will. However, my observations and also my reading of the code seems to indicate that it basically does _one_ item of work (handles a single event).
This makes it somewhat difficult to use in a polling mode application. I call libusb_handle_events_timeout() periodically, hoping to handle everything necessary. However, it seems like it "falls behind" in some cases, only handling some events (one event?) each time it's called, and if events arrive at a faster rate than the function is called, then it doesn't work.
Furthermore, I can't tell if any events were handled; otherwise, I could just keep looping and calling it until no more events are handled. I can tell whether any of my own callbacks are invoked, but that's not the whole story. For example if I have submitted a transfer with libusb_submit_transfer(), then it appears as if this requires processing in libusb_handle_events_timeout(). (I'm not 100% sure.)
I can try to provide a repro case. One way is to call libusb_submit_transfer() a lot to set up a whole pile of pending transfers, then call libusb_handle_events_timeout() -- only some of them (one of them?) actually get queued.
- I am on crack, libusb_handle_events_timeout() with a zero timeout definitely handles ALL pending events (unlike with a nonzero timeout, where it's documented to handle ONE pending event), and I should go soak my head and figure out the problem with my code;
- libusb_handle_events_timeout() with a zero timeout indeed only handles ONE pending event (or not all of them, anyway), in which case I think the documentation should be changed and a workaround identified for polling operation.
Thx for any help and/or head-soaking you can provide.