kike: put a timeout on shutdown

And kill all clients if it takes them too long.
This commit is contained in:
Přemysl Eric Janouch 2015-04-10 03:13:36 +02:00
parent 355ecaed47
commit dc08f9d5ab
1 changed files with 16 additions and 0 deletions

16
kike.c
View File

@ -530,6 +530,7 @@ struct server_context
struct str_map handlers; ///< Message handlers struct str_map handlers; ///< Message handlers
struct poller poller; ///< Manages polled description struct poller poller; ///< Manages polled description
struct poller_timer quit_timer; ///< Quit timeout timer
bool quitting; ///< User requested quitting bool quitting; ///< User requested quitting
bool polling; ///< The event loop is running bool polling; ///< The event loop is running
@ -544,6 +545,14 @@ struct server_context
struct str_map operators; ///< SSL cert. fingerprints for IRCops struct str_map operators; ///< SSL cert. fingerprints for IRCops
}; };
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 static void
server_context_init (struct server_context *self) server_context_init (struct server_context *self)
{ {
@ -564,6 +573,9 @@ server_context_init (struct server_context *self)
poller_init (&self->poller); poller_init (&self->poller);
self->quitting = false; self->quitting = false;
self->polling = 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); memset (&self->signal_event, 0, sizeof self->signal_event);
@ -631,7 +643,10 @@ static void
irc_try_finish_quit (struct server_context *ctx) irc_try_finish_quit (struct server_context *ctx)
{ {
if (!ctx->n_clients && ctx->quitting) if (!ctx->n_clients && ctx->quitting)
{
poller_timer_reset (&ctx->quit_timer);
ctx->polling = false; ctx->polling = false;
}
} }
static void static void
@ -652,6 +667,7 @@ irc_initiate_quit (struct server_context *ctx)
ctx->n_listen_fds = 0; ctx->n_listen_fds = 0;
ctx->quitting = true; ctx->quitting = true;
poller_timer_set (&ctx->quit_timer, 5000);
irc_try_finish_quit (ctx); irc_try_finish_quit (ctx);
} }