From 2b2b2762cc48f6be7a26c185bd95e7c77cdc46fa Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 9 Dec 2024 12:49:19 +0000 Subject: [Fix] Use cumulative timeout when dealing with TCP connections --- src/libutil/libev_helper.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/libutil/libev_helper.c') diff --git a/src/libutil/libev_helper.c b/src/libutil/libev_helper.c index 203e1ed73..82fead9bb 100644 --- a/src/libutil/libev_helper.c +++ b/src/libutil/libev_helper.c @@ -69,16 +69,21 @@ void rspamd_ev_watcher_start(struct ev_loop *loop, } } -void rspamd_ev_watcher_stop(struct ev_loop *loop, - struct rspamd_io_ev *ev) +ev_tstamp rspamd_ev_watcher_stop(struct ev_loop *loop, + struct rspamd_io_ev *ev) { + ev_tstamp elapsed = 0; + if (ev_can_stop(&ev->io)) { ev_io_stop(EV_A, &ev->io); } if (ev->timeout > 0) { + elapsed = ev->timeout - ev_timer_remaining(EV_A, &ev->tm); ev_timer_stop(EV_A, &ev->tm); } + + return elapsed; } void rspamd_ev_watcher_reschedule(struct ev_loop *loop, -- cgit v1.2.3