From: Steinar H. Gunderson Date: Sun, 7 Apr 2013 20:06:24 +0000 (+0200) Subject: Fix an issue where clients would be put twice into sleeping_clients (probably since... X-Git-Tag: 1.0.0~181 X-Git-Url: https://git.sesse.net/?p=cubemap;a=commitdiff_plain;h=f3ed48479f9209e708cd17698dc9e778e07284cd;hp=43be6b6e71a38923e923f33daa1fd1172bcdd539 Fix an issue where clients would be put twice into sleeping_clients (probably since the EPOLLOUT trigger would go off once unexpectedly), causing a chain reaction where we did tons of empty write() calls. --- diff --git a/server.cpp b/server.cpp index 54e6b5e..94350fa 100644 --- a/server.cpp +++ b/server.cpp @@ -404,7 +404,7 @@ sending_header_or_error_again: // This is postcondition #3. client->state = Client::SENDING_DATA; client->bytes_sent = client->stream->data_size; - sleeping_clients.push_back(client); + put_client_to_sleep(client); return; } case Client::SENDING_DATA: { @@ -412,6 +412,9 @@ sending_header_or_error_again: // but resync will be the mux's problem. const Stream *stream = client->stream; size_t bytes_to_send = stream->data_size - client->bytes_sent; + if (bytes_to_send == 0) { + return; + } if (bytes_to_send > BACKLOG_SIZE) { fprintf(stderr, "WARNING: fd %d lost %lld bytes, maybe too slow connection\n", client->sock,