summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2010-06-17 20:15:44 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-06-17 20:15:44 +0200
commit7d392652bae52b76cb5fe907cc1e86e0e0c4ced9 (patch)
treebdbc8271e1b2a85041f84cfefb37bd32c48a8c5c /src
parent6a8c74eb36ab93702c257f425832272cccb0cde8 (diff)
downloadmtdev-git-7d392652bae52b76cb5fe907cc1e86e0e0c4ced9.tar.gz
Add idle function
This patch adds the mtdev_idle() function, which checks the kernel device for activity. Useful when implementing timing logic. Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src')
-rw-r--r--src/iobuf.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/iobuf.c b/src/iobuf.c
index 6d238ec..83e531a 100644
--- a/src/iobuf.c
+++ b/src/iobuf.c
@@ -28,6 +28,18 @@
#include "iobuf.h"
#include "state.h"
+#include <poll.h>
+
+int mtdev_idle(struct mtdev *dev, int fd, int ms)
+{
+ struct mtdev_state *state = dev->state;
+ struct mtdev_iobuf *buf = &state->iobuf;
+ struct pollfd fds = { fd, POLLIN, 0 };
+ return evbuf_empty(&state->outbuf) &&
+ evbuf_empty(&state->inbuf) &&
+ buf->head == buf->tail &&
+ poll(&fds, 1, ms) <= 0;
+}
int mtdev_fetch(struct mtdev *dev, struct input_event *ev, int fd)
{