@cryptotaxi247 / netdata-1 / commits / 1d6bf329f

check if http headers have been sent and log an error if they dont

Costa Tsaousis (ktsaou) committed May 3, 2017 at 00:08 UTC 1d6bf329f797f78efc4e34ff7aa893dc19377690
1 file changed +12 -3
src/web_client.c
+12 -3
@@ -962,13 +962,22 @@ static inline void web_client_send_http_header(struct web_client *w) {
962
963 web_client_crock_socket(w);
964
965 - ssize_t bytes = send(w->ofd, buffer_tostring(w->response.header_output), buffer_strlen(w->response.header_output), 0);
965 + size_t count = 0;
966 + ssize_t bytes;
967 + while((bytes = send(w->ofd, buffer_tostring(w->response.header_output), buffer_strlen(w->response.header_output), 0)) == -1) {
968 + count++;
969 +
970 + if(count > 100 || (errno != EAGAIN && errno != EWOULDBLOCK)) {
971 + error("Cannot send HTTP headers to web client.");
972 + break;
973 + }
974 + }
975 +
976 if(bytes != (ssize_t) buffer_strlen(w->response.header_output)) {
977 if(bytes > 0)
978 w->stats_sent_bytes += bytes;
979
970 - debug(D_WEB_CLIENT, "%llu: HTTP Header failed to be sent (I sent %zu bytes but the system sent %zd bytes). Closing web client."
971 - , w->id
980 + error("HTTP headers failed to be sent (I sent %zu bytes but the system sent %zd bytes). Closing web client."
981 , buffer_strlen(w->response.header_output)
982 , bytes);
983