degesch: don't cache reconnect configuration

Also make sure the delay isn't negative.
This commit is contained in:
Přemysl Eric Janouch 2015-05-16 12:45:39 +02:00
parent c2c82d20dd
commit 87352b33d0
1 changed files with 7 additions and 13 deletions

View File

@ -1015,18 +1015,13 @@ struct server
char *name; ///< Server identifier
struct buffer *buffer; ///< The buffer for this server
// Configuration:
struct config_item_ *config; ///< Configuration root
bool reconnect; ///< Whether to reconnect on conn. fail.
unsigned long reconnect_delay; ///< Reconnect delay in seconds
bool manual_disconnect; ///< Don't reconnect
// Connection:
enum server_state state; ///< Connection state
struct connector *connector; ///< Connection establisher
bool manual_disconnect; ///< Don't reconnect after disconnect
int socket; ///< Socket FD of the server
struct str read_buffer; ///< Input yet to be processed
@ -1354,6 +1349,7 @@ static struct config_schema g_config_server[] =
{ .name = "reconnect_delay",
.comment = "Time between reconnecting",
.type = CONFIG_ITEM_INTEGER,
.validate = config_validate_nonnegative,
.default_ = "5" },
{ .name = "socks_host",
@ -2802,14 +2798,15 @@ static void
irc_queue_reconnect (struct server *s)
{
// As long as the user wants us to, that is
if (!s->reconnect)
if (!get_config_boolean (s->config, "reconnect"))
return;
int64_t delay = get_config_integer (s->config, "reconnect_delay");
// TODO: exponentional backoff
hard_assert (s->socket == -1);
hard_assert (s->state == IRC_DISCONNECTED);
buffer_send_status (s->ctx, s->buffer,
"Trying to reconnect in %ld seconds...", s->reconnect_delay);
poller_timer_set (&s->reconnect_tmr, s->reconnect_delay * 1000);
"Trying to reconnect in %ld seconds...", delay);
poller_timer_set (&s->reconnect_tmr, delay * 1000);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -6661,9 +6658,6 @@ create_server (struct app_context *ctx)
s->config = config_item_get (ctx->config.root, "server", NULL);
hard_assert (s->config != NULL);
s->reconnect = get_config_boolean (s->config, "reconnect");
s->reconnect_delay = get_config_integer (s->config, "reconnect_delay");
struct error *e = NULL;
if (!irc_autofill_user_info (s, &e))
{