summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kike.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/kike.c b/kike.c
index e2aca2d..127fcd2 100644
--- a/kike.c
+++ b/kike.c
@@ -530,6 +530,7 @@ struct server_context
struct str_map handlers; ///< Message handlers
struct poller poller; ///< Manages polled description
+ struct poller_timer quit_timer; ///< Quit timeout timer
bool quitting; ///< User requested quitting
bool polling; ///< The event loop is running
@@ -545,6 +546,14 @@ struct server_context
};
static void
+on_irc_quit_timeout (void *user_data)
+{
+ struct server_context *ctx = user_data;
+ // Clients are closed in server_context_free()
+ ctx->polling = false;
+}
+
+static void
server_context_init (struct server_context *self)
{
self->listen_fds = NULL;
@@ -564,6 +573,9 @@ server_context_init (struct server_context *self)
poller_init (&self->poller);
self->quitting = false;
self->polling = false;
+ poller_timer_init (&self->quit_timer, &self->poller);
+ self->quit_timer.dispatcher = on_irc_quit_timeout;
+ self->quit_timer.user_data = self;
memset (&self->signal_event, 0, sizeof self->signal_event);
@@ -631,7 +643,10 @@ static void
irc_try_finish_quit (struct server_context *ctx)
{
if (!ctx->n_clients && ctx->quitting)
+ {
+ poller_timer_reset (&ctx->quit_timer);
ctx->polling = false;
+ }
}
static void
@@ -652,6 +667,7 @@ irc_initiate_quit (struct server_context *ctx)
ctx->n_listen_fds = 0;
ctx->quitting = true;
+ poller_timer_set (&ctx->quit_timer, 5000);
irc_try_finish_quit (ctx);
}