summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2017-04-20 20:47:39 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2017-04-20 20:55:49 +0200
commit0981df485a2cead652817f14044a7842451a0bd4 (patch)
tree350ffc95f1dcd27b38ec005d55158ac5bb9e5c74
parent9f0c18cc41cc70e1f3b637d368a56940054cef44 (diff)
downloadxK-0981df485a2cead652817f14044a7842451a0bd4.tar.gz
xK-0981df485a2cead652817f14044a7842451a0bd4.tar.xz
xK-0981df485a2cead652817f14044a7842451a0bd4.zip
degesch: simplify quitting
- send a QUIT on C-c, too - shut down the connection on /disconnect, too Connection management is one of the few fucked up parts that remain in that state for historical reasons.
-rw-r--r--degesch.c85
1 files changed, 36 insertions, 49 deletions
diff --git a/degesch.c b/degesch.c
index ecd1226..80939fc 100644
--- a/degesch.c
+++ b/degesch.c
@@ -4837,36 +4837,6 @@ try_finish_quit (struct app_context *ctx)
}
static void
-initiate_quit (struct app_context *ctx)
-{
- log_global_status (ctx, "Shutting down");
-
- // Hide the user interface
- CALL (ctx->input, hide);
-
- // Initiate a connection close
- 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
- poller_timer_reset (&s->reconnect_tmr);
-
- if (irc_is_connected (s))
- {
- irc_shutdown (s);
- s->manual_disconnect = true;
- }
- else if (s->state == IRC_CONNECTING)
- irc_destroy_connector (s);
- }
-
- ctx->quitting = true;
- try_finish_quit (ctx);
-}
-
-static void
irc_destroy_transport (struct server *s)
{
if (s->transport
@@ -4954,13 +4924,46 @@ irc_initiate_disconnect (struct server *s, const char *reason)
log_server_error (s, s->buffer, "%s: %s", "Disconnected from server",
"connection torn down early per user request");
irc_disconnect (s);
+ return;
}
- else if (reason)
+
+ if (reason)
irc_send (s, "QUIT :%s", reason);
else
+ // TODO: make the default QUIT message customizable
+ // -> global/per server/both?
+ // -> implement IRC output hooks for plugins?
irc_send (s, "QUIT :%s", PROGRAM_NAME " " PROGRAM_VERSION);
s->manual_disconnect = true;
+ irc_shutdown (s);
+}
+
+static void
+initiate_quit (struct app_context *ctx, const char *message)
+{
+ log_global_status (ctx, "Shutting down");
+
+ // Hide the user interface
+ CALL (ctx->input, hide);
+
+ // Initiate a connection close
+ 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
+ poller_timer_reset (&s->reconnect_tmr);
+
+ if (irc_is_connected (s))
+ irc_initiate_disconnect (s, message);
+ else if (s->state == IRC_CONNECTING)
+ irc_destroy_connector (s);
+ }
+
+ ctx->quitting = true;
+ try_finish_quit (ctx);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -11131,18 +11134,7 @@ handle_command_me (struct handler_args *a)
static bool
handle_command_quit (struct handler_args *a)
{
- struct str_map_iter iter;
- str_map_iter_init (&iter, &a->ctx->servers);
-
- // FIXME: we should pass the message as an argument to initiate_quit()
- struct server *s;
- while ((s = str_map_iter_next (&iter)))
- {
- if (irc_is_connected (s))
- irc_initiate_disconnect (s, *a->arguments ? a->arguments : NULL);
- }
-
- initiate_quit (a->ctx);
+ initiate_quit (a->ctx, *a->arguments ? a->arguments : NULL);
return true;
}
@@ -13565,12 +13557,7 @@ on_signal_pipe_readable (const struct pollfd *fd, struct app_context *ctx)
;
if (g_termination_requested && !ctx->quitting)
- // 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);
-
+ initiate_quit (ctx, NULL);
if (g_winch_received)
{
redraw_screen (ctx);