eloop: allow NULL for timer updates

If NULL is passed for timer udpates, we simply assume that the timer
should be disarmed and use a zeroed itimerspec.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-09-27 12:54:37 +02:00
parent 3f4e8a498b
commit b3aba6f61c

View File

@ -1502,6 +1502,8 @@ err_cb:
timer->cb(timer, 0, timer->data);
}
static const struct itimerspec ev_timer_zero;
/**
* ev_timer_new:
* @out: Timer pointer where to store the new timer
@ -1525,6 +1527,9 @@ int ev_timer_new(struct ev_timer **out, const struct itimerspec *spec,
if (!out)
return llog_dEINVAL(log);
if (!spec)
spec = &ev_timer_zero;
timer = malloc(sizeof(*timer));
if (!timer)
return llog_dENOMEM(log);
@ -1694,8 +1699,9 @@ int ev_timer_update(struct ev_timer *timer, const struct itimerspec *spec)
if (!timer)
return -EINVAL;
if (!spec)
return llog_EINVAL(timer);
spec = &ev_timer_zero;
ret = timerfd_settime(timer->fd, 0, spec, NULL);
if (ret) {