Skip to content

Don't read events unless required

Peter Hutterer requested to merge whot/libevdev:wip/reduce-reads into master

With the previous approach, every libevdev_next_event() invocation triggered a read() on the device fd. This is not efficient, the kernel provides whole event frames at a time so we're guaranteed to have more events waiting unless the current event is a SYN_REPORT.

Assuming a fast-enough client and e.g. a touchpad device with multiple axes per frame, we'd thus trigger several unnecessary read() calls per event frame.

Drop this behavior, instead only trigger the read when our internal queue is empty and we need more events.


  • we don't have any warning about a too-slow sync, i.e. if a SYN_DROPPED arrives while we're syncing, we don't get a warning in the log anymore. the test for this was removed.
  • the tests that required the specific behavior were rewritten accordingly
  • a revoke on a kernel device doesn't return ENODEV until already-received events have been processed

The above shouldn't be an issue for existing real-world clients.

Fixes #7 (closed)

cc @bentiss

Merge request reports