@@ -108,4 +108,34 @@ void rspamd_ev_watcher_reschedule(struct ev_loop *loop, | |||
ev_timer_start(EV_A, &ev->tm); | |||
} | |||
} | |||
} | |||
void rspamd_ev_watcher_reschedule_at(struct ev_loop *loop, | |||
struct rspamd_io_ev *ev, | |||
short what, | |||
ev_tstamp at) | |||
{ | |||
g_assert(ev->cb != NULL); | |||
if (ev_can_stop(&ev->io)) { | |||
ev_io_stop(EV_A, &ev->io); | |||
ev_io_set(&ev->io, ev->io.fd, what); | |||
ev_io_start(EV_A, &ev->io); | |||
} | |||
else { | |||
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 (at > 0) { | |||
if (!(ev_can_stop(&ev->tm))) { | |||
/* Update timestamp to avoid timers running early */ | |||
ev_now_update_if_cheap(loop); | |||
ev->tm.data = ev; | |||
ev_timer_init(&ev->tm, rspamd_ev_watcher_timer_cb, at, 0.0); | |||
ev_timer_start(EV_A, &ev->tm); | |||
} | |||
} | |||
} |
@@ -1,11 +1,11 @@ | |||
/*- | |||
* Copyright 2019 Vsevolod Stakhov | |||
/* | |||
* Copyright 2024 Vsevolod Stakhov | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
@@ -79,6 +79,17 @@ void rspamd_ev_watcher_reschedule(struct ev_loop *loop, | |||
struct rspamd_io_ev *ev, | |||
short what); | |||
/** | |||
* Convenience function to reschedule watcher with different events and different timeout | |||
* @param loop | |||
* @param ev | |||
* @param what | |||
*/ | |||
void rspamd_ev_watcher_reschedule_at(struct ev_loop *loop, | |||
struct rspamd_io_ev *ev, | |||
short what, | |||
ev_tstamp at); | |||
#ifdef __cplusplus | |||
} | |||
#endif |