From fb4b087bf20e49722c190a495e552d5bc8148c03 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Sat, 19 May 2012 12:47:08 +0200 Subject: [PATCH] eloop: forward timer HUP and I/O errors to caller Similar to counter callbacks we now call timer callbacks with 0 as argument on errors and disable the timer source. Signed-off-by: David Herrmann --- src/eloop.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/eloop.c b/src/eloop.c index 1fd6927..7b39c92 100644 --- a/src/eloop.c +++ b/src/eloop.c @@ -752,21 +752,34 @@ static void timer_cb(struct ev_fd *fd, int mask, void *data) if (mask & (EV_HUP | EV_ERR)) { log_warn("HUP/ERR on timer source"); + if (timer->cb) + timer->cb(timer, 0, timer->data); return; } if (mask & EV_READABLE) { len = read(timer->fd, &expirations, sizeof(expirations)); if (len < 0) { - if (errno != EAGAIN) + if (errno != EAGAIN) { log_warning("cannot read timerfd (%d): %m", errno); + ev_timer_disable(timer); + if (timer->cb) + timer->cb(timer, 0, timer->data); + } } else if (len == 0) { log_warning("EOF on timer source"); + ev_timer_disable(timer); + if (timer->cb) + timer->cb(timer, 0, timer->data); } else if (len != sizeof(expirations)) { log_warn("invalid size %d read on timerfd", len); - } else if (timer->cb) { - timer->cb(timer, expirations, timer->data); + ev_timer_disable(timer); + if (timer->cb) + timer->cb(timer, 0, timer->data); + } else if (expirations > 0) { + if (timer->cb) + timer->cb(timer, expirations, timer->data); } } }