From ced2a57cfcf8f1ed45f93bc74a876a5eb2e9d0b3 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sat, 16 Jan 2016 04:18:21 +0100 Subject: kike: allow messages before protocol establishment We can just queue them. --- kike.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/kike.c b/kike.c index 79e21e5..9c349c0 100644 --- a/kike.c +++ b/kike.c @@ -829,7 +829,7 @@ client_get_mode (struct client *self) static void client_send_str (struct client *c, const struct str *s) { - hard_assert (c->initialized && !c->closing_link); + hard_assert (!c->closing_link); size_t old_sendq = c->write_buffer.len; // TODO: kill the connection above some "SendQ" threshold (careful!) @@ -933,15 +933,9 @@ client_kill (struct client *c, const char *reason) static void client_close_link (struct client *c, const char *reason) { - // Cannot push data to a client whose protocol we don't even know, - // at least not with current code (client_send_str(), on_client_ready()), - // which could possibly be solved by client_update_poller() not setting - // POLLOUT when the protocol hasn't been initialized yet. - // + // Let's just cut the connection, the client can try again later. // We also want to avoid accidentally setting poller events before // address resolution has finished. - // - // Let's just cut the connection, the client can try again later. if (!c->initialized) { client_kill (c, reason); @@ -3365,6 +3359,7 @@ on_client_ready (const struct pollfd *pfd, void *user_data) static void client_update_poller (struct client *c, const struct pollfd *pfd) { + // We must not poll for writing when the connection hasn't been initialized int new_events = POLLIN; if (c->ssl) { @@ -3375,7 +3370,7 @@ client_update_poller (struct client *c, const struct pollfd *pfd) if (c->ssl_rx_want_tx) new_events &= ~POLLIN; if (c->ssl_tx_want_rx) new_events &= ~POLLOUT; } - else if (c->write_buffer.len) + else if (c->initialized && c->write_buffer.len) new_events |= POLLOUT; hard_assert (new_events != 0); -- cgit v1.2.3-70-g09d2