degesch: refactor and fix reconnect delays
This commit is contained in:
parent
baacb27d4b
commit
5c0a2975e8
36
degesch.c
36
degesch.c
@ -3474,28 +3474,34 @@ irc_reset_connection_timeouts (struct server *s)
|
||||
poller_timer_set (&s->ping_tmr, (3 * 60 + 30) * 1000);
|
||||
}
|
||||
|
||||
static int64_t
|
||||
irc_get_reconnect_delay (struct server *s)
|
||||
{
|
||||
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");
|
||||
for (unsigned i = 0; i < s->reconnect_attempt; i++)
|
||||
delay *= delay_factor;
|
||||
|
||||
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;
|
||||
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++;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user