degesch: cleanup wrt. quitting
This commit is contained in:
parent
897bb00af1
commit
4dd2a80ba2
43
degesch.c
43
degesch.c
|
@ -2840,6 +2840,7 @@ irc_queue_reconnect (struct server *s)
|
||||||
int64_t delay = get_config_integer (s->config, "reconnect_delay");
|
int64_t delay = get_config_integer (s->config, "reconnect_delay");
|
||||||
|
|
||||||
// TODO: exponentional backoff
|
// TODO: exponentional backoff
|
||||||
|
// XXX: maybe add a state for when a connect is queued?
|
||||||
hard_assert (s->state == IRC_DISCONNECTED);
|
hard_assert (s->state == IRC_DISCONNECTED);
|
||||||
buffer_send_status (s->ctx, s->buffer,
|
buffer_send_status (s->ctx, s->buffer,
|
||||||
"Trying to reconnect in %ld seconds...", delay);
|
"Trying to reconnect in %ld seconds...", delay);
|
||||||
|
@ -3031,12 +3032,13 @@ irc_send (struct server *s, const char *format, ...)
|
||||||
static void
|
static void
|
||||||
irc_shutdown (struct server *s)
|
irc_shutdown (struct server *s)
|
||||||
{
|
{
|
||||||
// TODO: set a timer after which we cut the connection?
|
|
||||||
// Generally non-critical
|
// Generally non-critical
|
||||||
if (s->ssl)
|
if (s->ssl)
|
||||||
soft_assert (SSL_shutdown (s->ssl) != -1);
|
soft_assert (SSL_shutdown (s->ssl) != -1);
|
||||||
else
|
else
|
||||||
soft_assert (shutdown (s->socket, SHUT_WR) == 0);
|
soft_assert (shutdown (s->socket, SHUT_WR) == 0);
|
||||||
|
|
||||||
|
// TODO: set a timer after which we cut the connection
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -3072,21 +3074,27 @@ try_finish_quit (struct app_context *ctx)
|
||||||
static void
|
static void
|
||||||
initiate_quit (struct app_context *ctx)
|
initiate_quit (struct app_context *ctx)
|
||||||
{
|
{
|
||||||
|
buffer_send_status (ctx, ctx->global_buffer, "Shutting down");
|
||||||
|
|
||||||
// Destroy the user interface
|
// Destroy the user interface
|
||||||
input_stop (&ctx->input);
|
input_stop (&ctx->input);
|
||||||
|
|
||||||
buffer_send_status (ctx, ctx->global_buffer, "Shutting down");
|
|
||||||
|
|
||||||
// Initiate a connection close
|
|
||||||
struct str_map_iter iter;
|
struct str_map_iter iter;
|
||||||
str_map_iter_init (&iter, &ctx->servers);
|
str_map_iter_init (&iter, &ctx->servers);
|
||||||
|
|
||||||
|
// Initiate a connection close
|
||||||
struct server *s;
|
struct server *s;
|
||||||
while ((s = str_map_iter_next (&iter)))
|
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))
|
if (irc_is_connected (s))
|
||||||
|
{
|
||||||
// XXX: when we go async, we'll have to flush output buffers first
|
// XXX: when we go async, we'll have to flush output buffers first
|
||||||
irc_shutdown (s);
|
irc_shutdown (s);
|
||||||
|
s->manual_disconnect = true;
|
||||||
|
}
|
||||||
else if (s->state == IRC_CONNECTING)
|
else if (s->state == IRC_CONNECTING)
|
||||||
irc_destroy_connector (s);
|
irc_destroy_connector (s);
|
||||||
}
|
}
|
||||||
|
@ -7144,26 +7152,6 @@ setup_signal_handlers (void)
|
||||||
|
|
||||||
// --- I/O event handlers ------------------------------------------------------
|
// --- 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
|
static void
|
||||||
on_signal_pipe_readable (const struct pollfd *fd, struct app_context *ctx)
|
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);
|
(void) read (fd->fd, &dummy, 1);
|
||||||
|
|
||||||
if (g_termination_requested && !ctx->quitting)
|
if (g_termination_requested && !ctx->quitting)
|
||||||
{
|
// TODO: this way we don't send a QUIT message but just close the
|
||||||
preinitiate_quit (ctx);
|
// 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);
|
||||||
}
|
|
||||||
|
|
||||||
if (g_winch_received)
|
if (g_winch_received)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue