Browse Source

[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...
tags/3.2
Vsevolod Stakhov 2 years ago
parent
commit
d3a1896577
2 changed files with 7 additions and 18 deletions
  1. 7
    17
      src/libutil/libev_helper.c
  2. 0
    1
      src/libutil/libev_helper.h

+ 7
- 17
src/libutil/libev_helper.c View File

@@ -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);
}

+ 0
- 1
src/libutil/libev_helper.h View File

@@ -37,7 +37,6 @@ struct rspamd_io_ev {
ev_timer tm;
rspamd_ev_cb cb;
void *ud;
ev_tstamp last_activity;
ev_tstamp timeout;
};


Loading…
Cancel
Save