summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-07-18 13:39:30 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-07-18 13:39:30 +0200
commit5c0a2975e8f659971f885dda726719977df9ab6c (patch)
treeb81aa46f3211acede97e0cf4cd63db1d13d968c1
parentbaacb27d4b4bdacc9b9eb89311399964fc48dd98 (diff)
downloadxK-5c0a2975e8f659971f885dda726719977df9ab6c.tar.gz
xK-5c0a2975e8f659971f885dda726719977df9ab6c.tar.xz
xK-5c0a2975e8f659971f885dda726719977df9ab6c.zip
degesch: refactor and fix reconnect delays
-rw-r--r--degesch.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/degesch.c b/degesch.c
index b3e65fb..e90904a 100644
--- a/degesch.c
+++ b/degesch.c
@@ -3474,28 +3474,34 @@ irc_reset_connection_timeouts (struct server *s)
poller_timer_set (&s->ping_tmr, (3 * 60 + 30) * 1000);
}
-static void
-irc_queue_reconnect (struct server *s)
+static int64_t
+irc_get_reconnect_delay (struct server *s)
{
- // As long as the user wants us to, that is
- if (!get_config_boolean (s->config, "reconnect"))
- return;
int64_t delay = get_config_integer (s->config, "reconnect_delay");
int64_t delay_factor = get_config_integer (s->ctx->config.root,
"behaviour.reconnect_delay_growing");
- int64_t delay_max = get_config_integer (s->ctx->config.root,
- "behaviour.reconnect_delay_max");
-
for (unsigned i = 0; i < s->reconnect_attempt; i++)
delay *= delay_factor;
- if (delay > delay_max || delay < 0)
- delay = delay_max;
- s->reconnect_attempt++;
+ int64_t delay_max = get_config_integer (s->ctx->config.root,
+ "behaviour.reconnect_delay_max");
+ return (delay > delay_max || delay < 0) ? delay_max : delay;
+}
+
+static void
+irc_queue_reconnect (struct server *s)
+{
+ // As long as the user wants us to, that is
+ if (!get_config_boolean (s->config, "reconnect"))
+ return;
// XXX: maybe add a state for when a connect is queued?
hard_assert (s->state == IRC_DISCONNECTED);
+
+ int64_t delay = irc_get_reconnect_delay (s);
+ s->reconnect_attempt++;
+
log_server_status (s, s->buffer,
"Trying to reconnect in #&s seconds...",
xstrdup_printf ("%" PRId64, delay));
@@ -4449,8 +4455,6 @@ irc_initiate_connect (struct server *s)
return;
}
- s->reconnect_attempt = 0;
-
struct str_vector servers;
str_vector_init (&servers);
cstr_split_ignore_empty (addresses, ',', &servers);
@@ -7561,6 +7565,8 @@ handle_command_connect (struct handler_args *a)
irc_destroy_connector (s);
irc_cancel_timers (s);
+
+ s->reconnect_attempt = 0;
irc_initiate_connect (s);
return true;
}