summaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c43
1 files changed, 16 insertions, 27 deletions
diff --git a/degesch.c b/degesch.c
index 6ebb350..3efa0e2 100644
--- a/degesch.c
+++ b/degesch.c
@@ -2840,6 +2840,7 @@ irc_queue_reconnect (struct server *s)
int64_t delay = get_config_integer (s->config, "reconnect_delay");
// TODO: exponentional backoff
+ // XXX: maybe add a state for when a connect is queued?
hard_assert (s->state == IRC_DISCONNECTED);
buffer_send_status (s->ctx, s->buffer,
"Trying to reconnect in %ld seconds...", delay);
@@ -3031,12 +3032,13 @@ irc_send (struct server *s, const char *format, ...)
static void
irc_shutdown (struct server *s)
{
- // TODO: set a timer after which we cut the connection?
// Generally non-critical
if (s->ssl)
soft_assert (SSL_shutdown (s->ssl) != -1);
else
soft_assert (shutdown (s->socket, SHUT_WR) == 0);
+
+ // TODO: set a timer after which we cut the connection
}
static void
@@ -3072,21 +3074,27 @@ try_finish_quit (struct app_context *ctx)
static void
initiate_quit (struct app_context *ctx)
{
+ buffer_send_status (ctx, ctx->global_buffer, "Shutting down");
+
// Destroy the user interface
input_stop (&ctx->input);
- buffer_send_status (ctx, ctx->global_buffer, "Shutting down");
-
- // Initiate a connection close
struct str_map_iter iter;
str_map_iter_init (&iter, &ctx->servers);
+ // Initiate a connection close
struct server *s;
while ((s = str_map_iter_next (&iter)))
{
+ // There may be a timer set to reconnect to the server
+ poller_timer_reset (&s->reconnect_tmr);
+
if (irc_is_connected (s))
+ {
// XXX: when we go async, we'll have to flush output buffers first
irc_shutdown (s);
+ s->manual_disconnect = true;
+ }
else if (s->state == IRC_CONNECTING)
irc_destroy_connector (s);
}
@@ -7144,26 +7152,6 @@ setup_signal_handlers (void)
// --- I/O event handlers ------------------------------------------------------
-// FIXME: merge this with initiate_quit()
-static void
-preinitiate_quit (struct app_context *ctx)
-{
- struct str_map_iter iter;
- str_map_iter_init (&iter, &ctx->servers);
-
- struct server *s;
- while ((s = str_map_iter_next (&iter)))
- {
- // There may be a timer set to reconnect to the server
- // TODO: a faster timer for quitting
- // XXX: why do we do this? Just to reset the reconnect timer?
- irc_reset_connection_timeouts (s);
-
- if (irc_is_connected (s))
- irc_initiate_disconnect (s, NULL);
- }
-}
-
static void
on_signal_pipe_readable (const struct pollfd *fd, struct app_context *ctx)
{
@@ -7171,10 +7159,11 @@ on_signal_pipe_readable (const struct pollfd *fd, struct app_context *ctx)
(void) read (fd->fd, &dummy, 1);
if (g_termination_requested && !ctx->quitting)
- {
- preinitiate_quit (ctx);
+ // TODO: this way we don't send a QUIT message but just close the
+ // connection from our side and wait for a full close.
+ // Once we allow for custom quit messages, we will probably want to
+ // call irc_initiate_disconnect() for all servers.
initiate_quit (ctx);
- }
if (g_winch_received)
{