aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libcryptobox/keypairs_cache.c2
-rw-r--r--src/libserver/task.h4
-rw-r--r--src/libstat/backends/redis_backend.c46
-rw-r--r--src/libutil/CMakeLists.txt1
-rw-r--r--src/libutil/util.c18
-rw-r--r--src/libutil/util.h4
-rw-r--r--src/lua/lua_cdb.c10
7 files changed, 29 insertions, 56 deletions
diff --git a/src/libcryptobox/keypairs_cache.c b/src/libcryptobox/keypairs_cache.c
index 5e3a13e18..bcba5e247 100644
--- a/src/libcryptobox/keypairs_cache.c
+++ b/src/libcryptobox/keypairs_cache.c
@@ -14,9 +14,9 @@
* limitations under the License.
*/
#include "config.h"
-#include "rspamd.h"
#include "keypairs_cache.h"
#include "keypair_private.h"
+#include "libutil/util.h"
#include "hash.h"
struct rspamd_keypair_elt {
diff --git a/src/libserver/task.h b/src/libserver/task.h
index 736644126..ca42da6b3 100644
--- a/src/libserver/task.h
+++ b/src/libserver/task.h
@@ -200,8 +200,8 @@ struct rspamd_task {
struct rspamd_dns_resolver *resolver; /**< DNS resolver */
struct ev_loop *event_loop; /**< Event base */
- struct event timeout_ev; /**< Global task timeout */
- struct event *guard_ev; /**< Event for input sanity guard */
+ struct ev_timer timeout_ev; /**< Global task timeout */
+ struct ev_io *guard_ev; /**< Event for input sanity guard */
gpointer checkpoint; /**< Opaque checkpoint data */
ucl_object_t *settings; /**< Settings applied to task */
diff --git a/src/libstat/backends/redis_backend.c b/src/libstat/backends/redis_backend.c
index 937327c7f..b5f02c270 100644
--- a/src/libstat/backends/redis_backend.c
+++ b/src/libstat/backends/redis_backend.c
@@ -70,7 +70,7 @@ struct redis_stat_runtime {
struct redis_stat_ctx *ctx;
struct rspamd_task *task;
struct upstream *selected;
- struct event timeout_event;
+ ev_timer timeout_event;
GArray *results;
struct rspamd_statfile_config *stcf;
gchar *redis_object_expanded;
@@ -1019,8 +1019,8 @@ rspamd_redis_fin (gpointer data)
rt->has_event = FALSE;
/* Stop timeout */
- if (rspamd_event_pending (&rt->timeout_event, EV_TIMEOUT)) {
- event_del (&rt->timeout_event);
+ if (ev_is_active (&rt->timeout_event)) {
+ ev_timer_stop (rt->task->event_loop, &rt->timeout_event);
}
if (rt->redis) {
@@ -1052,9 +1052,9 @@ rspamd_redis_fin_learn (gpointer data)
}
static void
-rspamd_redis_timeout (gint fd, short what, gpointer d)
+rspamd_redis_timeout (EV_P_ ev_timer *w, int revents)
{
- struct redis_stat_runtime *rt = REDIS_RUNTIME (d);
+ struct redis_stat_runtime *rt = REDIS_RUNTIME (w->data);
struct rspamd_task *task;
redisAsyncContext *redis;
@@ -1562,7 +1562,6 @@ rspamd_redis_process_tokens (struct rspamd_task *task,
{
struct redis_stat_runtime *rt = REDIS_RUNTIME (p);
rspamd_fstring_t *query;
- struct timeval tv;
gint ret;
const gchar *learned_key = "learns";
@@ -1591,13 +1590,15 @@ rspamd_redis_process_tokens (struct rspamd_task *task,
rspamd_session_add_event (task->s, rspamd_redis_fin, rt, M);
rt->has_event = TRUE;
- if (rspamd_event_pending (&rt->timeout_event, EV_TIMEOUT)) {
- event_del (&rt->timeout_event);
+
+ if (ev_is_active (&rt->timeout_event)) {
+ ev_timer_again (task->event_loop, &rt->timeout_event);
+ }
+ else {
+ ev_timer_init (&rt->timeout_event, rspamd_redis_timeout,
+ rt->ctx->timeout, 0.);
+ ev_timer_start (task->event_loop, &rt->timeout_event);
}
- event_set (&rt->timeout_event, -1, EV_TIMEOUT, rspamd_redis_timeout, rt);
- event_base_set (task->event_loop, &rt->timeout_event);
- double_to_tv (rt->ctx->timeout, &tv);
- event_add (&rt->timeout_event, &tv);
query = rspamd_redis_tokens_to_query (task, rt, tokens,
rt->ctx->new_schema ? "HGET" : "HMGET",
@@ -1628,8 +1629,8 @@ rspamd_redis_finalize_process (struct rspamd_task *task, gpointer runtime,
struct redis_stat_runtime *rt = REDIS_RUNTIME (runtime);
redisAsyncContext *redis;
- if (rspamd_event_pending (&rt->timeout_event, EV_TIMEOUT)) {
- event_del (&rt->timeout_event);
+ if (ev_is_active (&rt->timeout_event)) {
+ ev_timer_stop (task->event_loop, &rt->timeout_event);
}
if (rt->redis) {
@@ -1802,13 +1803,14 @@ rspamd_redis_learn_tokens (struct rspamd_task *task, GPtrArray *tokens,
rt->has_event = TRUE;
/* Set timeout */
- if (rspamd_event_pending (&rt->timeout_event, EV_TIMEOUT)) {
- event_del (&rt->timeout_event);
+ if (ev_is_active (&rt->timeout_event)) {
+ ev_timer_again (task->event_loop, &rt->timeout_event);
+ }
+ else {
+ ev_timer_init (&rt->timeout_event, rspamd_redis_timeout,
+ rt->ctx->timeout, 0.);
+ ev_timer_start (task->event_loop, &rt->timeout_event);
}
- event_set (&rt->timeout_event, -1, EV_TIMEOUT, rspamd_redis_timeout, rt);
- event_base_set (task->event_loop, &rt->timeout_event);
- double_to_tv (rt->ctx->timeout, &tv);
- event_add (&rt->timeout_event, &tv);
return TRUE;
}
@@ -1827,8 +1829,8 @@ rspamd_redis_finalize_learn (struct rspamd_task *task, gpointer runtime,
struct redis_stat_runtime *rt = REDIS_RUNTIME (runtime);
redisAsyncContext *redis;
- if (rspamd_event_pending (&rt->timeout_event, EV_TIMEOUT)) {
- event_del (&rt->timeout_event);
+ if (ev_is_active (&rt->timeout_event)) {
+ ev_timer_stop (task->event_loop, &rt->timeout_event);
}
if (rt->redis) {
diff --git a/src/libutil/CMakeLists.txt b/src/libutil/CMakeLists.txt
index f86d650f0..fd29c5512 100644
--- a/src/libutil/CMakeLists.txt
+++ b/src/libutil/CMakeLists.txt
@@ -1,6 +1,7 @@
# Librspamd-util
SET(LIBRSPAMDUTILSRC
${CMAKE_CURRENT_SOURCE_DIR}/addr.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/libev_helper.c
${CMAKE_CURRENT_SOURCE_DIR}/aio_event.c
${CMAKE_CURRENT_SOURCE_DIR}/bloom.c
${CMAKE_CURRENT_SOURCE_DIR}/expression.c
diff --git a/src/libutil/util.c b/src/libutil/util.c
index c5fec19a7..665b6accb 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -2570,24 +2570,6 @@ rspamd_constant_memcmp (const guchar *a, const guchar *b, gsize len)
return (((gint32)(guint16)((guint32)r + 0x8000) - 0x8000) == 0);
}
-#if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000000UL
-struct ev_loop *
-event_get_base (struct event *ev)
-{
- return ev->ev_base;
-}
-#endif
-
-int
-rspamd_event_pending (struct event *ev, short what)
-{
- if (ev->ev_base == NULL) {
- return 0;
- }
-
- return event_pending (ev, what, NULL);
-}
-
int
rspamd_file_xopen (const char *fname, int oflags, guint mode,
gboolean allow_symlink)
diff --git a/src/libutil/util.h b/src/libutil/util.h
index 75f391482..b7d6055ce 100644
--- a/src/libutil/util.h
+++ b/src/libutil/util.h
@@ -426,10 +426,6 @@ void rspamd_random_seed_fast (void);
*/
gboolean rspamd_constant_memcmp (const guchar *a, const guchar *b, gsize len);
-
-/* Avoid stupidity in libevent > 1.4 */
-int rspamd_event_pending (struct event *ev, short what);
-
/**
* Open file without following symlinks or special stuff
* @param fname filename
diff --git a/src/lua/lua_cdb.c b/src/lua/lua_cdb.c
index a7292da03..0b8c27b2a 100644
--- a/src/lua/lua_cdb.c
+++ b/src/lua/lua_cdb.c
@@ -64,13 +64,12 @@ lua_cdb_create (lua_State *L)
else {
cdb = g_malloc (sizeof (struct cdb));
cdb->filename = g_strdup (filename);
- cdb->check_timer_ev = NULL;
- cdb->check_timer_tv = NULL;
if (cdb_init (cdb, fd) == -1) {
msg_warn ("cannot open cdb: %s, %s", filename, strerror (errno));
lua_pushnil (L);
}
else {
+ cdb_add_timer (cdb, ev_default_loop (0), CDB_REFRESH_TIME);
pcdb = lua_newuserdata (L, sizeof (struct cdb *));
rspamd_lua_setclass (L, "rspamd{cdb}", -1);
*pcdb = cdb;
@@ -106,13 +105,6 @@ lua_cdb_lookup (lua_State *L)
lua_error (L);
return 1;
}
- /*
- * XXX: this code is placed here because event_loop is called inside workers, so start
- * monitoring on first check, not on creation
- */
- if (cdb->check_timer_ev == NULL) {
- cdb_add_timer (cdb, CDB_REFRESH_TIME);
- }
what = luaL_checkstring (L, 2);
if (cdb_find (cdb, what, strlen (what)) > 0) {