diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-06-20 21:10:50 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-06-20 21:10:50 +0200 |
commit | 935d671a57e24d79201a129d3c7130d1da5273d9 (patch) | |
tree | d1e5496f13e7ff7f915be45ce45cd890d9fe45d0 /degesch.c | |
parent | 4970929f1d5fa1d7170d8419f49692b6476fe17d (diff) | |
download | xK-935d671a57e24d79201a129d3c7130d1da5273d9.tar.gz xK-935d671a57e24d79201a129d3c7130d1da5273d9.tar.xz xK-935d671a57e24d79201a129d3c7130d1da5273d9.zip |
degesch: shuffle some code
Diffstat (limited to 'degesch.c')
-rw-r--r-- | degesch.c | 80 |
1 files changed, 42 insertions, 38 deletions
@@ -1041,11 +1041,17 @@ struct server SSL_CTX *ssl_ctx; ///< SSL context SSL *ssl; ///< SSL connection - // TODO: an output queue to prevent excess floods (this will be needed - // especially for away status polling) + // Events: + + struct poller_timer ping_tmr; ///< We should send a ping + struct poller_timer timeout_tmr; ///< Connection seems to be dead + struct poller_timer reconnect_tmr; ///< We should reconnect now // IRC: + // TODO: an output queue to prevent excess floods (this will be needed + // especially for away status polling) + struct str_map irc_users; ///< IRC user data struct str_map irc_channels; ///< IRC channel data struct str_map irc_buffer_map; ///< Maps IRC identifiers to buffers @@ -1075,12 +1081,6 @@ struct server char *irc_chanuser_modes; ///< Channel user modes unsigned irc_max_modes; ///< Max parametrized modes per command - - // Events: - - struct poller_timer ping_tmr; ///< We should send a ping - struct poller_timer timeout_tmr; ///< Connection seems to be dead - struct poller_timer reconnect_tmr; ///< We should reconnect now }; static void on_irc_timeout (void *user_data); @@ -1096,6 +1096,25 @@ server_init (struct server *self, struct poller *poller) str_init (&self->read_buffer); self->state = IRC_DISCONNECTED; + poller_timer_init (&self->timeout_tmr, poller); + self->timeout_tmr.dispatcher = on_irc_timeout; + self->timeout_tmr.user_data = self; + + poller_timer_init (&self->ping_tmr, poller); + self->ping_tmr.dispatcher = on_irc_ping_timeout; + self->ping_tmr.user_data = self; + + poller_timer_init (&self->reconnect_tmr, poller); + self->reconnect_tmr.dispatcher = (poller_timer_fn) irc_initiate_connect; + self->reconnect_tmr.user_data = self; + + str_map_init (&self->irc_users); + self->irc_users.key_xfrm = irc_strxfrm; + str_map_init (&self->irc_channels); + self->irc_channels.key_xfrm = irc_strxfrm; + str_map_init (&self->irc_buffer_map); + self->irc_buffer_map.key_xfrm = irc_strxfrm; + str_init (&self->irc_user_mode); // Defaults as per the RPL_ISUPPORT drafts, or RFC 1459 @@ -1115,30 +1134,13 @@ server_init (struct server *self, struct poller *poller) self->irc_chanuser_modes = xstrdup ("ov"); self->irc_max_modes = 3; - - str_map_init (&self->irc_users); - self->irc_users.key_xfrm = irc_strxfrm; - str_map_init (&self->irc_channels); - self->irc_channels.key_xfrm = irc_strxfrm; - str_map_init (&self->irc_buffer_map); - self->irc_buffer_map.key_xfrm = irc_strxfrm; - - poller_timer_init (&self->timeout_tmr, poller); - self->timeout_tmr.dispatcher = on_irc_timeout; - self->timeout_tmr.user_data = self; - - poller_timer_init (&self->ping_tmr, poller); - self->ping_tmr.dispatcher = on_irc_ping_timeout; - self->ping_tmr.user_data = self; - - poller_timer_init (&self->reconnect_tmr, poller); - self->reconnect_tmr.dispatcher = (poller_timer_fn) irc_initiate_connect; - self->reconnect_tmr.user_data = self; } static void server_free (struct server *self) { + free (self->name); + if (self->connector) { connector_free (self->connector); @@ -1156,7 +1158,9 @@ server_free (struct server *self) if (self->ssl_ctx) SSL_CTX_free (self->ssl_ctx); - free (self->name); + str_map_free (&self->irc_users); + str_map_free (&self->irc_channels); + str_map_free (&self->irc_buffer_map); if (self->irc_user) user_unref (self->irc_user); @@ -1174,10 +1178,6 @@ server_free (struct server *self) free (self->irc_chanuser_prefixes); free (self->irc_chanuser_modes); - - str_map_free (&self->irc_users); - str_map_free (&self->irc_channels); - str_map_free (&self->irc_buffer_map); } static void @@ -3170,7 +3170,7 @@ on_irc_disconnected (struct server *s) { hard_assert (irc_is_connected (s)); - // Get rid of the dead socket and related things + // Get rid of the dead socket if (s->ssl) { SSL_free (s->ssl); @@ -3183,6 +3183,13 @@ on_irc_disconnected (struct server *s) s->socket = -1; s->state = IRC_DISCONNECTED; + s->read_event.closed = true; + poller_fd_reset (&s->read_event); + + // All of our timers have lost their meaning now + irc_cancel_timers (s); + + // Reset state bound to the connection struct str_map_iter iter; str_map_iter_init (&iter, &s->irc_channels); struct channel *channel; @@ -3199,12 +3206,9 @@ on_irc_disconnected (struct server *s) free (s->irc_user_host); s->irc_user_host = NULL; - s->read_event.closed = true; - poller_fd_reset (&s->read_event); - - // All of our timers have lost their meaning now - irc_cancel_timers (s); + // TODO: reset RPL_ISUPPORT information + // Take any relevant actions if (s->ctx->quitting) try_finish_quit (s->ctx); else if (s->manual_disconnect) |