From d52254b4ec9f125a96caa5afc37dc2b33ba38d4f Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Tue, 14 Nov 2017 08:46:22 +0100 Subject: [PATCH] Make sure to restart the I/O watcher on UEV_ERROR Signed-off-by: Joachim Nilsson --- examples/joystick.c | 12 ++++++++---- examples/redirect.c | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/joystick.c b/examples/joystick.c index 9513b7e..51d65e5 100644 --- a/examples/joystick.c +++ b/examples/joystick.c @@ -43,11 +43,15 @@ struct js_event { */ static void joystick_cb(uev_t *w, void *arg, int events) { - if (UEV_ERROR == events) - errx(EBADF, "Unrecoverable error, exiting"); + if (UEV_ERROR == events) { + warnx("Spurious problem with the joystick watcher, restarting."); + uev_io_start(w); + } - if (read(w->fd, &e, sizeof(e)) < 0) - errx(errno, "Failed reading joystick event"); + if (read(w->fd, &e, sizeof(e)) < 0) { + warn("Failed reading joystick event"); + return; + } switch (e.type) { case 1: diff --git a/examples/redirect.c b/examples/redirect.c index 6e890b3..a8aefa2 100644 --- a/examples/redirect.c +++ b/examples/redirect.c @@ -24,8 +24,10 @@ void process_stdin(uev_t *w, void *arg, int events) char buf[256]; int len; - if (UEV_ERROR == events) - errx(EBADF, "Unrecoverable error, exiting"); + if (UEV_ERROR == events) { + warnx("Spurious problem with the stdin watcher, restarting."); + uev_io_start(w); + } len = read(w->fd, buf, sizeof(buf)); if (len == -1) {