From d62c625535494361b8ba0a004a1d24ce485f0b59 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Fri, 18 Jun 2010 01:35:28 +0200 Subject: 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 --- include/mtdev.h | 9 +++++---- src/iobuf.c | 2 ++ 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) -- cgit v1.2.1