From: Vsevolod Stakhov Date: Sat, 26 Oct 2013 21:32:18 +0000 (+0100) Subject: Fix timeouts in map watch. X-Git-Tag: 0.6.0~100 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=47f9952f1a0580585feb1204976f21deb53a338e;p=rspamd.git Fix timeouts in map watch. --- diff --git a/src/map.c b/src/map.c index ea7f0adbb..7c61dcc9e 100644 --- a/src/map.c +++ b/src/map.c @@ -767,12 +767,12 @@ file_callback (gint fd, short what, void *ud) struct rspamd_map *map = ud; struct file_map_data *data = map->map_data; struct stat st; - gdouble jittered_msec; + gdouble jittered_sec; /* Plan event again with jitter */ evtimer_del (&map->ev); - jittered_msec = (map->cfg->map_timeout + g_random_double ()); - msec_to_tv (jittered_msec, &map->tv); + jittered_sec = (map->cfg->map_timeout + g_random_double () * map->cfg->map_timeout); + double_to_tv (jittered_sec, &map->tv); evtimer_add (&map->ev, &map->tv); @@ -900,12 +900,12 @@ http_callback (gint fd, short what, void *ud) struct http_map_data *data = map->map_data; gint sock; struct http_callback_data *cbd; - gdouble jittered_msec; + gdouble jittered_sec; /* Plan event again with jitter */ evtimer_del (&map->ev); - jittered_msec = (map->cfg->map_timeout + g_random_double ()); - msec_to_tv (jittered_msec, &map->tv); + jittered_sec = (map->cfg->map_timeout + g_random_double () * map->cfg->map_timeout); + double_to_tv (jittered_sec, &map->tv); evtimer_add (&map->ev, &map->tv); if (g_atomic_int_get (map->locked)) { @@ -944,7 +944,7 @@ start_map_watch (struct config_file *cfg, struct event_base *ev_base) GList *cur = cfg->maps; struct rspamd_map *map; struct file_map_data *fdata; - gdouble jittered_msec; + gdouble jittered_sec; /* First of all do synced read of data */ while (cur) { @@ -960,8 +960,8 @@ start_map_watch (struct config_file *cfg, struct event_base *ev_base) read_map_file (map, map->map_data); } /* Plan event with jitter */ - jittered_msec = (map->cfg->map_timeout + g_random_double ()) / 2.; - msec_to_tv (jittered_msec, &map->tv); + jittered_sec = (map->cfg->map_timeout + g_random_double () * map->cfg->map_timeout) / 2.; + double_to_tv (jittered_sec, &map->tv); evtimer_add (&map->ev, &map->tv); } else if (map->protocol == MAP_PROTO_HTTP) { @@ -970,8 +970,8 @@ start_map_watch (struct config_file *cfg, struct event_base *ev_base) /* Read initial data */ read_http_sync (map, map->map_data); /* Plan event with jitter */ - jittered_msec = (map->cfg->map_timeout + g_random_double ()); - msec_to_tv (jittered_msec, &map->tv); + jittered_sec = (map->cfg->map_timeout + g_random_double () * map->cfg->map_timeout); + double_to_tv (jittered_sec, &map->tv); evtimer_add (&map->ev, &map->tv); } cur = g_list_next (cur); diff --git a/src/util.h b/src/util.h index 405d289a3..2526a981a 100644 --- a/src/util.h +++ b/src/util.h @@ -216,6 +216,7 @@ gchar * escape_braces_addr_fstr (memory_pool_t *pool, f_str_t *in); * Convert milliseconds to timeval fields */ #define msec_to_tv(msec, tv) do { (tv)->tv_sec = (msec) / 1000; (tv)->tv_usec = ((msec) - (tv)->tv_sec * 1000) * 1000; } while(0) +#define double_to_tv(dbl, tv) do { (tv)->tv_sec = (int)(dbl); (tv)->tv_usec = ((dbl) - (int)(dbl))*1000*1000; } while(0) #define tv_to_msec(tv) (tv)->tv_sec * 1000 + (tv)->tv_usec / 1000 /* Compare two emails for building emails tree */