summaryrefslogtreecommitdiff
path: root/libevdev/libevdev.c
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2013-07-01 15:46:23 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2013-07-02 10:59:01 +1000
commitf3a6b0c6854a59f4433217f279f76383687d0c3b (patch)
treefbee861b3c9ce5545f4e3627687a18572f99876a /libevdev/libevdev.c
parenta10fc33cd8f3b12c7acd862ab0504b5465fb36ca (diff)
downloadlibevdev-f3a6b0c6854a59f4433217f279f76383687d0c3b.tar.gz
Add a flag for blocking read
Not all clients need nonblocking read, so add a flag to read in blocking mode. In that mode, events are only read from the fd when the queue is empty. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'libevdev/libevdev.c')
-rw-r--r--libevdev/libevdev.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c
index 590e2d6..b625934 100644
--- a/libevdev/libevdev.c
+++ b/libevdev/libevdev.c
@@ -556,18 +556,21 @@ int libevdev_next_event(struct libevdev *dev, unsigned int flags, struct input_e
update_state(dev, &e);
}
- /* FIXME: check for O_NONBLOCK and if not set, skip if we have an
- * event in the queue from the previous read.
- */
-
/* FIXME: if the first event after syncing is a SYN_DROPPED, log this */
/* Always read in some more events. Best case this smoothes over a potential SYN_DROPPED,
- worst case we don't read fast enough and end up with SYN_DROPPED anyway */
+ worst case we don't read fast enough and end up with SYN_DROPPED anyway.
+
+ Except if the fd is in blocking mode and we still have events from the last read, don't
+ read in any more.
+ */
do {
- rc = read_more_events(dev);
- if (rc < 0 && rc != -EAGAIN)
- goto out;
+ if (!(flags & LIBEVDEV_READ_BLOCKING) ||
+ queue_num_elements(dev) == 0) {
+ rc = read_more_events(dev);
+ if (rc < 0 && rc != -EAGAIN)
+ goto out;
+ }
if (flags & LIBEVDEV_FORCE_SYNC) {
dev->need_sync = 1;