Don't read events unless required
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 16 Jan 2019 03:55:25 +0000 (13:55 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 19 Mar 2019 01:02:52 +0000 (01:02 +0000)
commit76662deeff46090d1009d76dda06767af4d45511
tree018504b9836dbf61c16b119de1aec9a4a28ef4b4
parent951cd6a189329f35d2477210c8db36cfb1eb4d80
Don't read events unless required

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.

Fallout:
- 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.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
libevdev/libevdev.c
test/test-kernel.c
test/test-libevdev-events.c