kike: allow messages before protocol establishment

We can just queue them.
This commit is contained in:
Přemysl Eric Janouch 2016-01-16 04:18:21 +01:00
parent f36d66b0cb
commit ced2a57cfc
1 changed files with 4 additions and 9 deletions

13
kike.c
View File

@ -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);