diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-07-18 13:39:30 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-07-18 13:39:30 +0200 |
commit | 5c0a2975e8f659971f885dda726719977df9ab6c (patch) | |
tree | b81aa46f3211acede97e0cf4cd63db1d13d968c1 /degesch.c | |
parent | baacb27d4b4bdacc9b9eb89311399964fc48dd98 (diff) | |
download | xK-5c0a2975e8f659971f885dda726719977df9ab6c.tar.gz xK-5c0a2975e8f659971f885dda726719977df9ab6c.tar.xz xK-5c0a2975e8f659971f885dda726719977df9ab6c.zip |
degesch: refactor and fix reconnect delays
Diffstat (limited to 'degesch.c')
-rw-r--r-- | degesch.c | 32 |
1 files changed, 19 insertions, 13 deletions
@@ -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; } |