commit 005105a: [Project] Rework upstreams
Vsevolod Stakhov
vsevolod at highsecure.ru
Sat Jun 22 12:14:18 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-06-17 13:07:17 +0100
URL: https://github.com/rspamd/rspamd/commit/005105a1b0e0b8101ad641f892609c680af2f45f
[Project] Rework upstreams
---
src/libutil/upstream.c | 28 +++++++++++++---------------
src/libutil/upstream.h | 2 +-
2 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c
index 2a2934916..263f52511 100644
--- a/src/libutil/upstream.c
+++ b/src/libutil/upstream.c
@@ -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) {
diff --git a/src/libutil/upstream.h b/src/libutil/upstream.h
index 5fbec7ca1..89ac0ee9e 100644
--- a/src/libutil/upstream.h
+++ b/src/libutil/upstream.h
@@ -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);
/**
More information about the Commits
mailing list