From d3a1896577a0c8da2dc1d8908f99cbdbc0c23350 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 6 Jan 2022 15:12:50 +0000 Subject: [PATCH] [Rework] Timeouts are now global per event and not reseted by IO activity This actually reproduces old libevent behaviour and it was changed by a big design mistake. We really want IO timeouts to be fired for the whole set of subsequent events, otherwise it should be designed in a more configurable way... --- src/libutil/libev_helper.c | 24 +++++++----------------- src/libutil/libev_helper.h | 1 - 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/libutil/libev_helper.c b/src/libutil/libev_helper.c index 41195bfa6..315a15bc7 100644 --- a/src/libutil/libev_helper.c +++ b/src/libutil/libev_helper.c @@ -21,7 +21,6 @@ rspamd_ev_watcher_io_cb (EV_P_ struct ev_io *w, int revents) { struct rspamd_io_ev *ev = (struct rspamd_io_ev *)w->data; - ev->last_activity = ev_now (EV_A); ev->cb (ev->io.fd, revents, ev->ud); } @@ -30,17 +29,11 @@ rspamd_ev_watcher_timer_cb (EV_P_ struct ev_timer *w, int revents) { struct rspamd_io_ev *ev = (struct rspamd_io_ev *)w->data; - ev_tstamp after = ev->last_activity - ev_now (EV_A) + ev->timeout; - - if (after < 0.) { - /* Real timeout */ - ev->cb (ev->io.fd, EV_TIMER, ev->ud); - } - else { - /* Start another cycle as there was some activity */ - w->repeat = after; - ev_timer_again (EV_A_ w); - } + /* + * We now call timeout callback in all the cases, as we assume that all + * timeouts are final + */ + ev->cb (ev->io.fd, EV_TIMER, ev->ud); } @@ -66,12 +59,11 @@ rspamd_ev_watcher_start (struct ev_loop *loop, { g_assert (ev->cb != NULL); - ev->last_activity = ev_now (EV_A); ev_io_start (EV_A_ &ev->io); if (timeout > 0) { /* Update timestamp to avoid timers running early */ - ev_now_update (loop); + ev_now_update_if_cheap (loop); ev->timeout = timeout; ev_timer_set (&ev->tm, timeout, 0.0); @@ -113,13 +105,11 @@ rspamd_ev_watcher_reschedule (struct ev_loop *loop, if (ev->timeout > 0) { if (!(ev_can_stop (&ev->tm))) { /* Update timestamp to avoid timers running early */ - ev_now_update (loop); + ev_now_update_if_cheap (loop); ev->tm.data = ev; ev_timer_init (&ev->tm, rspamd_ev_watcher_timer_cb, ev->timeout, 0.0); ev_timer_start (EV_A_ &ev->tm); } } - - ev->last_activity = ev_now (EV_A); } \ No newline at end of file diff --git a/src/libutil/libev_helper.h b/src/libutil/libev_helper.h index 8502043e6..fc344736f 100644 --- a/src/libutil/libev_helper.h +++ b/src/libutil/libev_helper.h @@ -37,7 +37,6 @@ struct rspamd_io_ev { ev_timer tm; rspamd_ev_cb cb; void *ud; - ev_tstamp last_activity; ev_tstamp timeout; }; -- 2.39.5