diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-10 03:13:36 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-10 03:13:36 +0200 |
commit | dc08f9d5ab3182de4211c50c3c4c4cd3314fa171 (patch) | |
tree | 4bef6dd6424a8666c754200255926bfff6731b38 | |
parent | 355ecaed47092566657f4c7004724aad17b9d006 (diff) | |
download | xK-dc08f9d5ab3182de4211c50c3c4c4cd3314fa171.tar.gz xK-dc08f9d5ab3182de4211c50c3c4c4cd3314fa171.tar.xz xK-dc08f9d5ab3182de4211c50c3c4c4cd3314fa171.zip |
kike: put a timeout on shutdown
And kill all clients if it takes them too long.
-rw-r--r-- | kike.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -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); } |