]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Rework upstreams
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 17 Jun 2019 12:07:17 +0000 (13:07 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 22 Jun 2019 09:57:29 +0000 (10:57 +0100)
src/libutil/upstream.c
src/libutil/upstream.h

index 2a29349166b37874875f4bcbeb88c92aec6c1789..263f52511508c4779cf40446fdf09f218ca12c29 100644 (file)
@@ -50,7 +50,7 @@ struct upstream {
        guint dns_requests;
        gint active_idx;
        gchar *name;
-       struct event ev;
+       ev_timer ev;
        gdouble last_fail;
        gpointer ud;
        struct upstream_list *ls;
@@ -92,7 +92,7 @@ struct upstream_list {
 
 struct upstream_ctx {
        struct rdns_resolver *res;
-       struct ev_loop *ev_base;
+       struct ev_loop *event_loop;
        struct upstream_limits limits;
        GQueue *upstreams;
        gboolean configured;
@@ -119,7 +119,7 @@ static guint default_dns_retransmits = 2;
 void
 rspamd_upstreams_library_config (struct rspamd_config *cfg,
                                                                 struct upstream_ctx *ctx,
-                                                                struct ev_loop *ev_base,
+                                                                struct ev_loop *event_loop,
                                                                 struct rdns_resolver *resolver)
 {
        g_assert (ctx != NULL);
@@ -141,7 +141,7 @@ rspamd_upstreams_library_config (struct rspamd_config *cfg,
                ctx->limits.dns_timeout = cfg->dns_timeout;
        }
 
-       ctx->ev_base = ev_base;
+       ctx->event_loop = event_loop;
        ctx->res = resolver;
        ctx->configured = TRUE;
 }
@@ -366,12 +366,12 @@ rspamd_upstream_dns_cb (struct rdns_reply *reply, void *arg)
 }
 
 static void
-rspamd_upstream_revive_cb (int fd, short what, void *arg)
+rspamd_upstream_revive_cb (struct ev_loop *loop, ev_timer *w, int revents)
 {
-       struct upstream *up = (struct upstream *)arg;
+       struct upstream *up = (struct upstream *)w->data;
 
        RSPAMD_UPSTREAM_LOCK (up->lock);
-       event_del (&up->ev);
+       ev_timer_stop (loop, w);
        if (up->ls) {
                rspamd_upstream_set_active (up->ls, up);
        }
@@ -414,7 +414,6 @@ rspamd_upstream_set_inactive (struct upstream_list *ls, struct upstream *up)
        gdouble ntim;
        guint i;
        struct upstream *cur;
-       struct timeval tv;
        struct upstream_list_watcher *w;
 
        RSPAMD_UPSTREAM_LOCK (ls->lock);
@@ -431,15 +430,14 @@ rspamd_upstream_set_inactive (struct upstream_list *ls, struct upstream *up)
                rspamd_upstream_resolve_addrs (ls, up);
 
                REF_RETAIN (up);
-               evtimer_set (&up->ev, rspamd_upstream_revive_cb, up);
-               if (up->ctx->ev_base != NULL && up->ctx->configured) {
-                       event_base_set (up->ctx->ev_base, &up->ev);
-               }
-
                ntim = rspamd_time_jitter (ls->limits.revive_time,
                                ls->limits.revive_jitter);
-               double_to_tv (ntim, &tv);
-               event_add (&up->ev, &tv);
+               ev_timer_init (&up->ev, rspamd_upstream_revive_cb, ntim, 0);
+               up->ev.data = up;
+
+               if (up->ctx->event_loop != NULL && up->ctx->configured) {
+                       ev_timer_start (up->ctx->event_loop, &up->ev);
+               }
        }
 
        DL_FOREACH (up->ls->watchers, w) {
index 5fbec7ca1a7774d08b0862a1145af6ef57e10f90..89ac0ee9e731dbb99e87a7b47c4a7a9f0f2e6b6e 100644 (file)
@@ -41,7 +41,7 @@ void rspamd_upstreams_library_unref (struct upstream_ctx *ctx);
  * @param cfg
  */
 void rspamd_upstreams_library_config (struct rspamd_config *cfg,
-               struct upstream_ctx *ctx, struct ev_loop *ev_base,
+               struct upstream_ctx *ctx, struct ev_loop *event_loop,
                struct rdns_resolver *resolver);
 
 /**