summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-05-16 12:45:39 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-05-16 12:45:39 +0200
commit87352b33d05af4863e8f0fc7c589f5c4cfe8cedf (patch)
tree11a7fc975f1e1e1c1d06a98c472d9b7ba788cef8
parentc2c82d20dd0f508c0fd928e2b192fe821e84b990 (diff)
downloadxK-87352b33d05af4863e8f0fc7c589f5c4cfe8cedf.tar.gz
xK-87352b33d05af4863e8f0fc7c589f5c4cfe8cedf.tar.xz
xK-87352b33d05af4863e8f0fc7c589f5c4cfe8cedf.zip
degesch: don't cache reconnect configuration
Also make sure the delay isn't negative.
-rw-r--r--degesch.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/degesch.c b/degesch.c
index b336938..2259e68 100644
--- a/degesch.c
+++ b/degesch.c
@@ -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))
{