Ticket #123 (new defect)
Opened 8 months ago
Last modified 8 months ago
libusb_handle_events_timeout() only handles one event
| Reported by: | egnor | Owned by: | |
|---|---|---|---|
| Component: | libusb-1.0 | Keywords: | |
| Cc: | egnor@… | Blocked By: | |
| Blocks: |
Description
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.
So, either:
- 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.
Change History
comment:1 in reply to: ↑ description Changed 8 months ago by stuge
comment:2 Changed 8 months ago by egnor
Happy to do so!
I was sort of hoping someone could authoritatively tell me what the behavior is supposed to be. I'm not sure if this is a doc bug, a real bug, or a feature. :-) Once I know the intent, I can try to verify/modify as appropriate.
Replying to egnor:
Could also be that the code should be fixed, if it doesn't handle all events. Please feel free to have a look into the libusb.git testing branch, and attach a documentation patch to this ticket according to what you find. Thanks!