From b3aba6f61caad9100f1f938c47619a421fcbd114 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Thu, 27 Sep 2012 12:54:37 +0200 Subject: [PATCH] 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 --- src/eloop.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/eloop.c b/src/eloop.c index c097292..1bf9ff7 100644 --- a/src/eloop.c +++ b/src/eloop.c @@ -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) { -- 2.7.4