@cryptotaxi247 / netdata-1 / commits / 6fe56a423

code cleanup for web_client

Costa Tsaousis committed May 29, 2016 at 18:18 UTC 6fe56a42353db61532d568b1df285086180f702f
2 files changed +33 -29
src/web_client.c
+29 -25
@@ -101,7 +101,8 @@ struct web_client *web_client_create(int listener)
101 }
102
103 int flag = 1;
104 - if(setsockopt(w->ifd, SOL_SOCKET, SO_KEEPALIVE, (char *) &flag, sizeof(int)) != 0) error("%llu: Cannot set SO_KEEPALIVE on socket.", w->id);
104 + if(setsockopt(w->ifd, SOL_SOCKET, SO_KEEPALIVE, (char *) &flag, sizeof(int)) != 0)
105 + error("%llu: Cannot set SO_KEEPALIVE on socket.", w->id);
106 }
107
108 w->response.data = buffer_create(INITIAL_WEB_DATA_LENGTH);
@@ -268,7 +269,7 @@ uid_t web_files_uid(void)
269 // while single threaded
270 struct passwd *pw = getpwnam(web_owner);
271 if(!pw) {
271 - error("User %s is not present. Ignoring option.", web_owner);
272 + error("User '%s' is not present. Ignoring option.", web_owner);
273 owner_uid = geteuid();
274 }
275 else {
@@ -296,7 +297,7 @@ gid_t web_files_gid(void)
297 // while single threaded
298 struct group *gr = getgrnam(web_group);
299 if(!gr) {
299 - error("Group %s is not present. Ignoring option.", web_group);
300 + error("Group '%s' is not present. Ignoring option.", web_group);
301 owner_gid = getegid();
302 }
303 else {
@@ -432,12 +433,12 @@ int mysendfile(struct web_client *w, char *filename)
433
434 #ifdef NETDATA_WITH_ZLIB
435 void web_client_enable_deflate(struct web_client *w, int gzip) {
435 - if(w->response.zinitialized) {
436 + if(unlikely(w->response.zinitialized)) {
437 error("%llu: Compression has already be initialized for this client.", w->id);
438 return;
439 }
440
440 - if(w->response.sent) {
441 + if(unlikely(w->response.sent)) {
442 error("%llu: Cannot enable compression in the middle of a conversation.", w->id);
443 return;
444 }
@@ -765,7 +766,7 @@ int web_client_api_request_v1_data(struct web_client *w, char *url)
766
767 if(outFileName && *outFileName) {
768 buffer_sprintf(w->response.header, "Content-Disposition: attachment; filename=\"%s\"\r\n", outFileName);
768 - error("generating outfilename header: '%s'", outFileName);
769 + debug(D_WEB_CLIENT, "%llu: generating outfilename header: '%s'", w->id, outFileName);
770 }
771
772 if(format == DATASOURCE_DATATABLE_JSONP) {
@@ -1739,7 +1740,7 @@ void web_client_process(struct web_client *w) {
1740 if(bytes > 0)
1741 w->stats_sent_bytes += bytes;
1742
1742 - error("%llu: HTTP Header failed to be sent (I sent %d bytes but the system sent %d bytes). Closing web client.", w->id,
1743 + debug(D_WEB_CLIENT, "%llu: HTTP Header failed to be sent (I sent %d bytes but the system sent %d bytes). Closing web client.", w->id,
1744 buffer_strlen(w->response.header_output), bytes);
1745
1746 WEB_CLIENT_IS_DEAD(w);
@@ -1750,7 +1751,8 @@ void web_client_process(struct web_client *w) {
1751
1752 /* // enable TCP_NODELAY, to send all data immediately at the next send()
1753 flag = 1;
1753 - if(setsockopt(w->ofd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)) != 0) error("%llu: failed to enable TCP_NODELAY on socket.", w->id);
1754 + if(setsockopt(w->ofd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)) != 0)
1755 + error("%llu: failed to enable TCP_NODELAY on socket.", w->id);
1756 */
1757 // enable sending immediately if we have data
1758 if(w->response.data->len) w->wait_send = 1;
@@ -1777,8 +1779,10 @@ void web_client_process(struct web_client *w) {
1779 // when it is commented, the program will copy the data using async I/O.
1780 {
1781 long len = sendfile(w->ofd, w->ifd, NULL, w->response.data->rbytes);
1780 - if(len != w->response.data->rbytes) error("%llu: sendfile() should copy %ld bytes, but copied %ld. Falling back to manual copy.", w->id, w->response.data->rbytes, len);
1781 - else web_client_reset(w);
1782 + if(len != w->response.data->rbytes)
1783 + error("%llu: sendfile() should copy %ld bytes, but copied %ld. Falling back to manual copy.", w->id, w->response.data->rbytes, len);
1784 + else
1785 + web_client_reset(w);
1786 }
1787 */
1788 }
@@ -1805,11 +1809,11 @@ ssize_t web_client_send_chunk_header(struct web_client *w, size_t len)
1809 }
1810
1811 else if(bytes == 0) {
1808 - error("%llu: Did not send chunk header to the client.", w->id);
1812 + debug(D_WEB_CLIENT, "%llu: Did not send chunk header to the client.", w->id);
1813 WEB_CLIENT_IS_DEAD(w);
1814 }
1815 else {
1812 - error("%llu: Failed to send chunk header to client.", w->id);
1816 + debug(D_WEB_CLIENT, "%llu: Failed to send chunk header to client.", w->id);
1817 WEB_CLIENT_IS_DEAD(w);
1818 }
1819
@@ -1827,11 +1831,11 @@ ssize_t web_client_send_chunk_close(struct web_client *w)
1831 }
1832
1833 else if(bytes == 0) {
1830 - error("%llu: Did not send chunk suffix to the client.", w->id);
1834 + debug(D_WEB_CLIENT, "%llu: Did not send chunk suffix to the client.", w->id);
1835 WEB_CLIENT_IS_DEAD(w);
1836 }
1837 else {
1834 - error("%llu: Failed to send chunk suffix to client.", w->id);
1838 + debug(D_WEB_CLIENT, "%llu: Failed to send chunk suffix to client.", w->id);
1839 WEB_CLIENT_IS_DEAD(w);
1840 }
1841
@@ -1849,11 +1853,11 @@ ssize_t web_client_send_chunk_finalize(struct web_client *w)
1853 }
1854
1855 else if(bytes == 0) {
1852 - error("%llu: Did not send chunk suffix to the client.", w->id);
1856 + debug(D_WEB_CLIENT, "%llu: Did not send chunk finalize suffix to the client.", w->id);
1857 WEB_CLIENT_IS_DEAD(w);
1858 }
1859 else {
1856 - error("%llu: Failed to send chunk suffix to client.", w->id);
1860 + debug(D_WEB_CLIENT, "%llu: Failed to send chunk finalize suffix to client.", w->id);
1861 WEB_CLIENT_IS_DEAD(w);
1862 }
1863
@@ -1963,11 +1967,11 @@ ssize_t web_client_send_deflate(struct web_client *w)
1967 debug(D_WEB_CLIENT, "%llu: Sent %d bytes.", w->id, len);
1968 }
1969 else if(len == 0) {
1966 - error("%llu: Did not send any bytes to the client (zhave = %ld, zsent = %ld, need to send = %ld).", w->id, w->response.zhave, w->response.zsent, w->response.zhave - w->response.zsent);
1970 + debug(D_WEB_CLIENT, "%llu: Did not send any bytes to the client (zhave = %ld, zsent = %ld, need to send = %ld).", w->id, w->response.zhave, w->response.zsent, w->response.zhave - w->response.zsent);
1971 WEB_CLIENT_IS_DEAD(w);
1972 }
1973 else {
1970 - error("%llu: Failed to send data to client.", w->id);
1974 + debug(D_WEB_CLIENT, "%llu: Failed to send data to client.", w->id);
1975 WEB_CLIENT_IS_DEAD(w);
1976 }
1977
@@ -2016,11 +2020,11 @@ ssize_t web_client_send(struct web_client *w) {
2020 debug(D_WEB_CLIENT, "%llu: Sent %d bytes.", w->id, bytes);
2021 }
2022 else if(likely(bytes == 0)) {
2019 - error("%llu: Did not send any bytes to the client.", w->id);
2023 + debug(D_WEB_CLIENT, "%llu: Did not send any bytes to the client.", w->id);
2024 WEB_CLIENT_IS_DEAD(w);
2025 }
2026 else {
2023 - error("%llu: Failed to send data to client.", w->id);
2027 + debug(D_WEB_CLIENT, "%llu: Failed to send data to client.", w->id);
2028 WEB_CLIENT_IS_DEAD(w);
2029 }
2030
@@ -2075,12 +2079,12 @@ ssize_t web_client_receive(struct web_client *w)
2079 w->ifd = w->ofd;
2080 }
2081 else {
2078 - error("%llu: failed to receive data.", w->id);
2082 + debug(D_WEB_CLIENT, "%llu: failed to receive data.", w->id);
2083 WEB_CLIENT_IS_DEAD(w);
2084 }
2085 }
2086 else {
2083 - error("%llu: receive data failed.", w->id);
2087 + debug(D_WEB_CLIENT, "%llu: receive data failed.", w->id);
2088 WEB_CLIENT_IS_DEAD(w);
2089 }
2090
@@ -2112,11 +2116,11 @@ void *web_client_main(void *ptr)
2116
2117 for(;;) {
2118 if(unlikely(w->dead)) {
2115 - error("%llu: client is dead.", w->id);
2119 + debug(D_WEB_CLIENT, "%llu: client is dead.", w->id);
2120 break;
2121 }
2122 else if(unlikely(!w->wait_receive && !w->wait_send)) {
2119 - error("%llu: client is not set for neither receiving nor sending data.");
2123 + debug(D_WEB_CLIENT, "%llu: client is not set for neither receiving nor sending data.");
2124 break;
2125 }
2126
@@ -2168,7 +2172,7 @@ void *web_client_main(void *ptr)
2172 continue;
2173 }
2174
2171 - error("%llu: LISTENER: poll() failed (input fd = %d, output fd = %d). Closing client.", w->id, w->ifd, w->ofd);
2175 + debug(D_WEB_CLIENT, "%llu: LISTENER: poll() failed (input fd = %d, output fd = %d). Closing client.", w->id, w->ifd, w->ofd);
2176 break;
2177 }
2178 else if(unlikely(!retval)) {
src/web_server.c
+4 -4
@@ -231,7 +231,7 @@ void *socket_listen_main_multi_threaded(void *ptr) {
231 retval = poll(&fd, 1, timeout);
232
233 if(unlikely(retval == -1)) {
234 - error("LISTENER: poll() failed.");
234 + debug(D_WEB_CLIENT, "LISTENER: poll() failed.");
235 failures++;
236
237 if(failures > 10) {
@@ -298,7 +298,7 @@ void *socket_listen_main_multi_threaded(void *ptr) {
298 failures = 0;
299 }
300
301 - error("LISTENER: exit!");
301 + debug(D_WEB_CLIENT, "LISTENER: exit!");
302 close(listen_fd);
303 listen_fd = -1;
304 return NULL;
@@ -391,7 +391,7 @@ void *socket_listen_main_single_threaded(void *ptr) {
391 retval = select(fdmax+1, &rifds, &rofds, &refds, &tv);
392
393 if(unlikely(retval == -1)) {
394 - error("LISTENER: select() failed.");
394 + debug(D_WEB_CLIENT, "LISTENER: select() failed.");
395 failures++;
396 if(failures > 10) {
397 if(global_statistics.connected_clients) {
@@ -483,7 +483,7 @@ void *socket_listen_main_single_threaded(void *ptr) {
483 }
484 }
485
486 - error("LISTENER: exit!");
486 + debug(D_WEB_CLIENT, "LISTENER: exit!");
487 close(listen_fd);
488 listen_fd = -1;
489 return NULL;