commit 76530e7: [Minor] Fix some more issues with timeouts

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Jun 22 12:14:56 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-06-21 16:03:59 +0100
URL: https://github.com/rspamd/rspamd/commit/76530e7356c3741bb91e482b4727f1fab68c817a

[Minor] Fix some more issues with timeouts

---
 src/libutil/libev_helper.c | 12 ++++++++----
 src/lua/lua_tcp.c          |  2 ++
 src/rspamadm/lua_repl.c    |  2 +-
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/libutil/libev_helper.c b/src/libutil/libev_helper.c
index 45e118e28..8a2cdc677 100644
--- a/src/libutil/libev_helper.c
+++ b/src/libutil/libev_helper.c
@@ -98,13 +98,17 @@ rspamd_ev_watcher_reschedule (struct ev_loop *loop,
 		ev_io_start (EV_A_ &ev->io);
 	}
 	else {
-		ev_io_set (&ev->io, ev->io.fd, what);
+		ev->io.data = ev;
+		ev_io_init (&ev->io, rspamd_ev_watcher_io_cb, ev->io.fd, what);
 		ev_io_start (EV_A_ &ev->io);
 	}
 
-	if (!(ev_is_active (&ev->tm) || ev_is_pending (&ev->tm))) {
-		ev_timer_set (&ev->tm, ev->timeout, 0.0);
-		ev_timer_start (EV_A_ &ev->tm);
+	if (ev->timeout > 0) {
+		if (!(ev_is_active (&ev->tm) || ev_is_pending (&ev->tm))) {
+			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);
diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c
index ab00548a0..b45d5b645 100644
--- a/src/lua/lua_tcp.c
+++ b/src/lua/lua_tcp.c
@@ -1275,6 +1275,8 @@ lua_tcp_make_connection (struct lua_tcp_cbdata *cbd)
 		}
 	}
 	else {
+		rspamd_ev_watcher_init (&cbd->ev, cbd->fd, EV_READ|EV_WRITE,
+				lua_tcp_handler, cbd);
 		lua_tcp_register_event (cbd);
 		lua_tcp_plan_handler_event (cbd, TRUE, TRUE);
 	}
diff --git a/src/rspamadm/lua_repl.c b/src/rspamadm/lua_repl.c
index 46fc342ea..59e3db02c 100644
--- a/src/rspamadm/lua_repl.c
+++ b/src/rspamadm/lua_repl.c
@@ -296,7 +296,7 @@ wait_session_events (void)
 {
 	/* XXX: it's probably worth to add timeout here - not to wait forever */
 	while (rspamd_session_events_pending (rspamadm_session) > 0) {
-		ev_loop (rspamd_main->event_loop, EVLOOP_ONESHOT);
+		ev_loop (rspamd_main->event_loop, EVRUN_ONCE);
 	}
 }
 


More information about the Commits mailing list