@cryptotaxi247 / netdata-1 / commits / 2af71a661

added make options nozlib=1 to compile without any external dependencies - of course with compression disabled

Costa Tsaousis (ktsaou) committed Oct 19, 2015 at 01:29 UTC 2af71a661fa0bd677c6fddf6f5170ea266d8b8fb
5 files changed +60 -22
Makefile
+5 -1
@@ -20,7 +20,11 @@ ifdef debug
20 COMMON_FLAGS += debug=1
21 endif
22
23 -all:
23 +ifdef nozlib
24 +COMMON_FLAGS += nozlib=1
25 +endif
26 +
27 +all:
28 $(MAKE) -C src $(COMMON_FLAGS) all
29
30 clean:
src/Makefile
+11 -1
@@ -22,11 +22,15 @@ ifdef nofork
22 NETDATA_NO_DAEMON = 1
23 endif
24
25 +ifdef nozlib
26 +NETDATA_WITHOUT_ZLIB = 1
27 +endif
28 +
29 COMMON_FLAGS = BIN_DIR='$(BIN_DIR)' CONFIG_DIR='$(CONFIG_DIR)' LOG_DIR='$(LOG_DIR)' PLUGINS_DIR='$(PLUGINS_DIR)'
30
31 proc_sources = proc_net_dev.c proc_net_ip_vs_stats.c proc_diskstats.c proc_meminfo.c proc_net_netstat.c proc_net_snmp.c proc_net_stat_conntrack.c proc_stat.c proc_vmstat.c proc_net_rpc_nfsd.c proc_sys_kernel_random_entropy_avail.c proc_interrupts.c
32 sources = avl.c dictionary.c procfile.c common.c log.c popen.c url.c config.c web_buffer.c storage_number.c web_client.c global_statistics.c rrd.c rrd2json.c web_server.c plugins_d.c daemon.c plugin_tc.c plugin_checks.c plugin_idlejitter.c plugin_proc.c unit_test.c main.c
29 -libs = -pthread -lz
33 +libs = -pthread
34
35 ifdef debug
36 COMMON_FLAGS += debug=1
@@ -48,6 +52,12 @@ ifdef NETDATA_NO_DAEMON
52 CFLAGS += -DNETDATA_NO_DAEMON=1
53 endif
54
55 +ifdef NETDATA_WITHOUT_ZLIB
56 +CFLAGS += -DNETDATA_WITHOUT_ZLIB=1
57 +else
58 +libs += -lz
59 +endif
60 +
61 # nfacct requires root access, so we prefer it as a plugin.d external plugin
62 ifdef INTERNAL_PLUGIN_NFACCT
63 CFLAGS += -DINTERNAL_PLUGIN_NFACCT=1
src/web_client.c
+37 -20
@@ -1,6 +1,7 @@
1 // enable strcasestr()
2 #define _GNU_SOURCE
3
4 +#include <unistd.h>
5 #include <stdlib.h>
6 #include <sys/types.h>
7 #include <sys/socket.h>
@@ -224,22 +225,28 @@ void web_client_reset(struct web_client *w)
225 struct timeval tv;
226 gettimeofday(&tv, NULL);
227
227 - long sent = w->zoutput?(long)w->zstream.total_out:((w->mode == WEB_CLIENT_MODE_FILECOPY)?w->data->rbytes:w->data->bytes);
228 + long sent = (w->mode == WEB_CLIENT_MODE_FILECOPY)?w->data->rbytes:w->data->bytes;
229 +
230 +#ifndef NETDATA_WITHOUT_ZLIB
231 + if(likely(w->zoutput)) sent = (long)w->zstream.total_out;
232 +#endif
233 +
234 long size = (w->mode == WEB_CLIENT_MODE_FILECOPY)?w->data->rbytes:w->data->bytes;
235
230 - if(w->last_url[0]) log_access("%llu: (sent/all = %ld/%ld bytes %0.0f%%, prep/sent/total = %0.2f/%0.2f/%0.2f ms) %s: '%s'",
231 - w->id,
232 - sent, size, -((size>0)?((float)(size-sent)/(float)size * 100.0):0.0),
233 - (float)usecdiff(&w->tv_ready, &w->tv_in) / 1000.0,
234 - (float)usecdiff(&tv, &w->tv_ready) / 1000.0,
235 - (float)usecdiff(&tv, &w->tv_in) / 1000.0,
236 - (w->mode == WEB_CLIENT_MODE_FILECOPY)?"filecopy":"data",
237 - w->last_url
236 + if(likely(w->last_url[0]))
237 + log_access("%llu: (sent/all = %ld/%ld bytes %0.0f%%, prep/sent/total = %0.2f/%0.2f/%0.2f ms) %s: '%s'",
238 + w->id,
239 + sent, size, -((size>0)?((float)(size-sent)/(float)size * 100.0):0.0),
240 + (float)usecdiff(&w->tv_ready, &w->tv_in) / 1000.0,
241 + (float)usecdiff(&tv, &w->tv_ready) / 1000.0,
242 + (float)usecdiff(&tv, &w->tv_in) / 1000.0,
243 + (w->mode == WEB_CLIENT_MODE_FILECOPY)?"filecopy":"data",
244 + w->last_url
245 );
246
247 debug(D_WEB_CLIENT, "%llu: Reseting client.", w->id);
248
242 - if(w->mode == WEB_CLIENT_MODE_FILECOPY) {
249 + if(unlikely(w->mode == WEB_CLIENT_MODE_FILECOPY)) {
250 debug(D_WEB_CLIENT, "%llu: Closing filecopy input file.", w->id);
251 close(w->ifd);
252 w->ifd = w->ofd;
@@ -260,11 +267,13 @@ void web_client_reset(struct web_client *w)
267 w->wait_receive = 1;
268 w->wait_send = 0;
269
270 + w->zoutput = 0;
271 +
272 // if we had enabled compression, release it
273 +#ifndef NETDATA_WITHOUT_ZLIB
274 if(w->zinitialized) {
275 debug(D_DEFLATE, "%llu: Reseting compression.", w->id);
276 deflateEnd(&w->zstream);
267 - w->zoutput = 0;
277 w->zsent = 0;
278 w->zhave = 0;
279 w->zstream.avail_in = 0;
@@ -273,8 +282,10 @@ void web_client_reset(struct web_client *w)
282 w->zstream.total_out = 0;
283 w->zinitialized = 0;
284 }
285 +#endif // NETDATA_WITHOUT_ZLIB
286 }
287
288 +#ifndef NETDATA_WITHOUT_ZLIB
289 void web_client_enable_deflate(struct web_client *w) {
290 if(w->zinitialized == 1) {
291 error("%llu: Compression has already be initialized for this client.", w->id);
@@ -319,6 +330,7 @@ void web_client_enable_deflate(struct web_client *w) {
330
331 debug(D_DEFLATE, "%llu: Initialized compression.", w->id);
332 }
333 +#endif // NETDATA_WITHOUT_ZLIB
334
335 int web_client_data_request(struct web_client *w, char *url, int datasource_type)
336 {
@@ -543,9 +555,11 @@ void web_client_process(struct web_client *w) {
555 if(strcasestr(w->data->buffer, "Connection: keep-alive")) w->keepalive = 1;
556 else w->keepalive = 0;
557
558 +#ifndef NETDATA_WITHOUT_ZLIB
559 // check if the client accepts deflate
560 if(web_enable_gzip && strstr(w->data->buffer, "gzip"))
561 web_client_enable_deflate(w);
562 +#endif // NETDATA_WITHOUT_ZLIB
563
564 int datasource_type = DATASOURCE_GOOGLE_JSONP;
565 //if(strstr(w->data->buffer, "X-DataSource-Auth"))
@@ -974,6 +988,7 @@ long web_client_send_chunk_finalize(struct web_client *w)
988 return bytes;
989 }
990
991 +#ifndef NETDATA_WITHOUT_ZLIB
992 long web_client_send_deflate(struct web_client *w)
993 {
994 long bytes = 0, t = 0;
@@ -1074,14 +1089,17 @@ long web_client_send_deflate(struct web_client *w)
1089
1090 return(bytes);
1091 }
1092 +#endif // NETDATA_WITHOUT_ZLIB
1093
1094 long web_client_send(struct web_client *w)
1095 {
1080 - if(w->zoutput) return web_client_send_deflate(w);
1096 +#ifndef NETDATA_WITHOUT_ZLIB
1097 + if(likely(w->zoutput)) return web_client_send_deflate(w);
1098 +#endif // NETDATA_WITHOUT_ZLIB
1099
1100 long bytes;
1101
1084 - if(w->data->bytes - w->data->sent == 0) {
1102 + if(unlikely(w->data->bytes - w->data->sent == 0)) {
1103 // there is nothing to send
1104
1105 debug(D_WEB_CLIENT, "%llu: Out of output data.", w->id);
@@ -1097,7 +1115,7 @@ long web_client_send(struct web_client *w)
1115 return(0);
1116 }
1117
1100 - if(w->keepalive == 0) {
1118 + if(unlikely(w->keepalive == 0)) {
1119 debug(D_WEB_CLIENT, "%llu: Closing (keep-alive is not enabled). %ld bytes sent.", w->id, w->data->sent);
1120 errno = 0;
1121 return(-1);
@@ -1109,14 +1127,13 @@ long web_client_send(struct web_client *w)
1127 }
1128
1129 bytes = send(w->ofd, &w->data->buffer[w->data->sent], w->data->bytes - w->data->sent, MSG_DONTWAIT);
1112 - if(bytes > 0) {
1130 + if(likely(bytes > 0)) {
1131 w->data->sent += bytes;
1132 debug(D_WEB_CLIENT, "%llu: Sent %d bytes.", w->id, bytes);
1133 }
1116 - else if(bytes == 0) debug(D_WEB_CLIENT, "%llu: Did not send any bytes to the client.", w->id);
1134 + else if(likely(bytes == 0)) debug(D_WEB_CLIENT, "%llu: Did not send any bytes to the client.", w->id);
1135 else debug(D_WEB_CLIENT, "%llu: Failed to send data to client. Reason: %s", w->id, strerror(errno));
1136
1119 -
1137 return(bytes);
1138 }
1139
@@ -1128,12 +1145,12 @@ long web_client_receive(struct web_client *w)
1145 long left = w->data->size - w->data->bytes;
1146 long bytes;
1147
1131 - if(w->mode == WEB_CLIENT_MODE_FILECOPY)
1148 + if(unlikely(w->mode == WEB_CLIENT_MODE_FILECOPY))
1149 bytes = read(w->ifd, &w->data->buffer[w->data->bytes], (left-1));
1150 else
1151 bytes = recv(w->ifd, &w->data->buffer[w->data->bytes], left-1, MSG_DONTWAIT);
1152
1136 - if(bytes > 0) {
1153 + if(likely(bytes > 0)) {
1154 int old = w->data->bytes;
1155 w->data->bytes += bytes;
1156 w->data->buffer[w->data->bytes] = '\0';
@@ -1146,7 +1163,7 @@ long web_client_receive(struct web_client *w)
1163 if(w->data->rbytes && w->data->bytes >= w->data->rbytes) w->wait_receive = 0;
1164 }
1165 }
1149 - else if(bytes == 0) {
1166 + else if(likely(bytes == 0)) {
1167 debug(D_WEB_CLIENT, "%llu: Out of input data.", w->id);
1168
1169 // if we cannot read, it means we have an error on input.
src/web_client.h
+6
@@ -1,4 +1,8 @@
1 +
2 +#ifndef NETDATA_WITHOUT_ZLIB
3 #include <zlib.h>
4 +#endif
5 +
6 #include <sys/time.h>
7 #include <string.h>
8 #include <sys/socket.h>
@@ -68,11 +72,13 @@ struct web_client {
72 struct web_buffer *data;
73
74 int zoutput; // if set to 1, web_client_send() will send compressed data
75 +#ifndef NETDATA_WITHOUT_ZLIB
76 z_stream zstream; // zlib stream for sending compressed output to client
77 Bytef zbuffer[ZLIB_CHUNK]; // temporary buffer for storing compressed output
78 long zsent; // the compressed bytes we have sent to the client
79 long zhave; // the compressed bytes that we have to send
80 int zinitialized;
81 +#endif
82
83 int wait_receive;
84 int wait_send;
src/web_server.c
+1
@@ -1,6 +1,7 @@
1 // enable strcasestr()
2 #define _GNU_SOURCE
3
4 +#include <unistd.h>
5 #include <stdlib.h>
6 #include <sys/types.h>
7 #include <sys/socket.h>