Refactor 2f9cce9, stop timers and try to restart signal watchers

In 2f9cce9 the invalidate_watcher() function was introduced to stop
invalid timer/cron and signal watchers.  This patch refactors that
change to instead call the stop method for cron/timer and attempt to
restart failing signal watchers.

The cron/timer and signal watchers are quite different from regular
I/O watchers in that their internal "fd" is hidden from and not under
the control of the user, so we should try to handle them better.  For
the former two we cannot do much other than stop and call the user's
registered callback with UEV_ERROR, but for the latter we can at least
try to restart it.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2017-11-13 14:52:16 +01:00
1 parent 3e5694cb76
commit d9f8caf0e8
1 file changed
+13 -15
+13 -15
View File
@@ -74,14 +74,6 @@ static int has_data(int fd)
return 0;
}
/* Set error condition and remove watcher from set */
static void invalidate_watcher(uev_t *w, struct epoll_event *event)
{
event->events = UEV_ERROR;
w->active = 0;
LIST_REMOVE(w, link);
}
/* Private to libuEv, do not use directly! */
int _uev_watcher_init(uev_ctx_t *ctx, uev_t *w, uev_type_t type, uev_cb_t *cb, void *arg, int fd, int events)
{
@@ -368,10 +360,11 @@ int uev_run(uev_ctx_t *ctx, int flags)
uint64_t exp;
if (read(w->fd, &exp, sizeof(exp)) != sizeof(exp)) {
if (errno != ECANCELED)
invalidate_watcher(w, &events[i]);
else
events[i].events = UEV_HUP;
events[i].events = UEV_HUP;
if (errno != ECANCELED) {
uev_cron_stop(w);
events[i].events = UEV_ERROR;
}
}
if (!w->u.c.interval)
@@ -384,7 +377,8 @@ int uev_run(uev_ctx_t *ctx, int flags)
uint64_t exp;
if (read(w->fd, &exp, sizeof(exp)) != sizeof(exp)) {
invalidate_watcher(w, &events[i]);
uev_timer_stop(w);
events[i].events = UEV_ERROR;
}
if (!w->u.t.period)
@@ -395,8 +389,12 @@ int uev_run(uev_ctx_t *ctx, int flags)
struct signalfd_siginfo fdsi;
ssize_t sz = sizeof(fdsi);
if (read(w->fd, &fdsi, sz) != sz)
invalidate_watcher(w, &events[i]);
if (read(w->fd, &fdsi, sz) != sz) {
if (uev_signal_start(w)) {
uev_signal_stop(w);
events[i].events = UEV_ERROR;
}
}
}
if (w->cb)