summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2010-06-18 01:35:28 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-06-18 01:35:28 +0200
commitd62c625535494361b8ba0a004a1d24ce485f0b59 (patch)
treea71299aa8fe70455663a9854ae26011691c0353b
parentc9c4f4cda362679567bc4bc04ffedc5d984e2329 (diff)
downloadmtdev-git-d62c625535494361b8ba0a004a1d24ce485f0b59.tar.gz
Allow max_events to be zero in mtdev_pull()
When reading from non-blocking devices, it makes sense to read all events available. This patch lets a zero max_events achieve that. Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
-rw-r--r--include/mtdev.h9
-rw-r--r--src/iobuf.c2
2 files changed, 7 insertions, 4 deletions
diff --git a/include/mtdev.h b/include/mtdev.h
index abb76da..7d442f1 100644
--- a/include/mtdev.h
+++ b/include/mtdev.h
@@ -189,12 +189,13 @@ void mtdev_put(struct mtdev *dev, const struct input_event *ev);
* mtdev_pull - pull events from the kernel device
* @dev: the mtdev in use
* @fd: file descriptor of the kernel device
- * @max_events: max number of events to read
+ * @max_events: max number of events to read (zero for all)
*
* Read a maxmimum of max_events events from the device, and put them
- * in the converter. The read operation behaves as dictated by the
- * file descriptior; if O_NONBLOCK is not set, the read will block
- * until max_events events are available or the buffer is full.
+ * in the converter. If max_events is zero, all available events will
+ * be read. The read operation behaves as dictated by the file
+ * descriptior; if O_NONBLOCK is not set, the read will block until
+ * max_events events are available or the buffer is full.
*
* On success, returns the number of events read. Otherwise, a standard
* negative error number is returned.
diff --git a/src/iobuf.c b/src/iobuf.c
index 199e0d8..6516a2c 100644
--- a/src/iobuf.c
+++ b/src/iobuf.c
@@ -68,6 +68,8 @@ int mtdev_pull(struct mtdev *dev, int fd, int max_events)
struct mtdev_state *state = dev->state;
struct input_event ev;
int ret, count = 0;
+ if (max_events <= 0)
+ max_events = DIM_EVENTS;
while (max_events-- && !evbuf_full(&state->inbuf)) {
ret = mtdev_fetch(dev, fd, &ev);
if (ret < 0)