diff options
Diffstat (limited to 'src/lua/lua_redis.c')
-rw-r--r-- | src/lua/lua_redis.c | 55 |
1 files changed, 23 insertions, 32 deletions
diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c index b96171d89..f39168a27 100644 --- a/src/lua/lua_redis.c +++ b/src/lua/lua_redis.c @@ -98,7 +98,7 @@ struct lua_redis_userdata { struct rspamd_task *task; struct rspamd_symcache_item *item; struct rspamd_async_session *s; - struct ev_loop *ev_base; + struct ev_loop *event_loop; struct rspamd_config *cfg; struct rspamd_redis_pool *pool; gchar *server; @@ -124,7 +124,7 @@ struct lua_redis_request_specific_userdata { struct lua_redis_userdata *c; struct lua_redis_ctx *ctx; struct lua_redis_request_specific_userdata *next; - struct event timeout; + ev_timer timeout_ev; guint flags; }; @@ -184,9 +184,7 @@ lua_redis_dtor (struct lua_redis_ctx *ctx) if (ud->ctx) { LL_FOREACH_SAFE (ud->specific, cur, tmp) { - if (rspamd_event_pending (&cur->timeout, EV_TIMEOUT)) { - event_del (&cur->timeout); - } + ev_timer_stop (ud->event_loop, &cur->timeout_ev); if (!(cur->flags & LUA_REDIS_SPECIFIC_REPLIED)) { is_successful = FALSE; @@ -245,9 +243,7 @@ lua_redis_fin (void *arg) ctx = sp_ud->ctx; - if (rspamd_event_pending (&sp_ud->timeout, EV_TIMEOUT)) { - event_del (&sp_ud->timeout); - } + ev_timer_stop (sp_ud->ctx->async.event_loop, &sp_ud->timeout_ev); msg_debug ("finished redis query %p from session %p", sp_ud, ctx); sp_ud->flags |= LUA_REDIS_SPECIFIC_FINISHED; @@ -556,10 +552,7 @@ lua_redis_callback_sync (redisAsyncContext *ac, gpointer r, gpointer priv) return; } - if (rspamd_event_pending (&sp_ud->timeout, EV_TIMEOUT)) { - event_del (&sp_ud->timeout); - } - + ev_timer_stop (ud->event_loop, &sp_ud->timeout_ev); msg_debug ("got reply from redis: %p for query %p", ac, sp_ud); struct lua_redis_result *result = g_malloc0 (sizeof *result); @@ -630,9 +623,10 @@ lua_redis_callback_sync (redisAsyncContext *ac, gpointer r, gpointer priv) } static void -lua_redis_timeout_sync (int fd, short what, gpointer priv) +lua_redis_timeout_sync (EV_P_ ev_timer *w, int revents) { - struct lua_redis_request_specific_userdata *sp_ud = priv; + struct lua_redis_request_specific_userdata *sp_ud = + (struct lua_redis_request_specific_userdata *)w->data; struct lua_redis_ctx *ctx = sp_ud->ctx; redisAsyncContext *ac; @@ -657,9 +651,10 @@ lua_redis_timeout_sync (int fd, short what, gpointer priv) } static void -lua_redis_timeout (int fd, short what, gpointer u) +lua_redis_timeout (EV_P_ ev_timer *w, int revents) { - struct lua_redis_request_specific_userdata *sp_ud = u; + struct lua_redis_request_specific_userdata *sp_ud = + (struct lua_redis_request_specific_userdata *)w->data; struct lua_redis_ctx *ctx; redisAsyncContext *ac; @@ -790,9 +785,9 @@ lua_redis_parse_args (lua_State *L, gint idx, const gchar *cmd, static struct lua_redis_ctx * rspamd_lua_redis_prepare_connection (lua_State *L, gint *pcbref, gboolean is_async) { - struct lua_redis_ctx *ctx; + struct lua_redis_ctx *ctx = NULL; rspamd_inet_addr_t *ip = NULL; - struct lua_redis_userdata *ud; + struct lua_redis_userdata *ud = NULL; struct rspamd_lua_ip *addr = NULL; struct rspamd_task *task = NULL; const gchar *host; @@ -933,7 +928,7 @@ rspamd_lua_redis_prepare_connection (lua_State *L, gint *pcbref, gboolean is_asy ud->s = session; ud->cfg = cfg; ud->pool = cfg->redis_pool; - ud->ev_base = ev_base; + ud->event_loop = ev_base; ud->task = task; if (task) { @@ -1009,7 +1004,6 @@ lua_redis_make_request (lua_State *L) struct lua_redis_userdata *ud; struct lua_redis_ctx *ctx, **pctx; const gchar *cmd = NULL; - struct timeval tv; gdouble timeout = REDIS_DEFAULT_TIMEOUT; gint cbref = -1; gboolean ret = FALSE; @@ -1064,10 +1058,9 @@ lua_redis_make_request (lua_State *L) REDIS_RETAIN (ctx); /* Cleared by fin event */ ctx->cmds_pending ++; - double_to_tv (timeout, &tv); - event_set (&sp_ud->timeout, -1, EV_TIMEOUT, lua_redis_timeout, sp_ud); - event_base_set (ud->ev_base, &sp_ud->timeout); - event_add (&sp_ud->timeout, &tv); + sp_ud->timeout_ev.data = sp_ud; + ev_timer_init (&sp_ud->timeout_ev, lua_redis_timeout, timeout, 0.0); + ev_timer_start (ud->event_loop, &sp_ud->timeout_ev); ret = TRUE; } else { @@ -1347,7 +1340,6 @@ lua_redis_add_cmd (lua_State *L) const gchar *cmd = NULL; gint args_pos = 2; gint cbref = -1, ret; - struct timeval tv; if (ctx) { if (ctx->flags & LUA_REDIS_TERMINATED) { @@ -1426,19 +1418,18 @@ lua_redis_add_cmd (lua_State *L) } } - double_to_tv (sp_ud->c->timeout, &tv); + sp_ud->timeout_ev.data = sp_ud; if (IS_ASYNC (ctx)) { - event_set (&sp_ud->timeout, -1, EV_TIMEOUT, - lua_redis_timeout, sp_ud); + ev_timer_init (&sp_ud->timeout_ev, lua_redis_timeout, + sp_ud->c->timeout, 0.0); } else { - event_set (&sp_ud->timeout, -1, EV_TIMEOUT, - lua_redis_timeout_sync, sp_ud); + ev_timer_init (&sp_ud->timeout_ev, lua_redis_timeout_sync, + sp_ud->c->timeout, 0.0); } - event_base_set (ud->ev_base, &sp_ud->timeout); - event_add (&sp_ud->timeout, &tv); + ev_timer_start (ud->event_loop, &sp_ud->timeout_ev); REDIS_RETAIN (ctx); ctx->cmds_pending ++; } |