]> arthur.barton.de Git - netdata.git/commitdiff
added make options nozlib=1 to compile without any external dependencies - of course...
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 18 Oct 2015 22:29:23 +0000 (01:29 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 18 Oct 2015 22:29:23 +0000 (01:29 +0300)
Makefile
src/Makefile
src/web_client.c
src/web_client.h
src/web_server.c

index 28943b469abbad6f4025af1b4b7356259477ea46..052dff92685a0ce725385f6d059d60f2866b26e1 100755 (executable)
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,11 @@ ifdef debug
 COMMON_FLAGS += debug=1\r
 endif\r
 \r
-all: \r
+ifdef nozlib\r
+COMMON_FLAGS += nozlib=1\r
+endif\r
+\r
+all:\r
        $(MAKE) -C src $(COMMON_FLAGS) all\r
 \r
 clean:\r
index 739812bf34b7c54b6dfb24edc3eeb6ec9765e255..a097b0d09ebde89312d0663a245d9b8f8664085d 100755 (executable)
@@ -22,11 +22,15 @@ ifdef nofork
 NETDATA_NO_DAEMON = 1
 endif
 
+ifdef nozlib
+NETDATA_WITHOUT_ZLIB = 1
+endif
+
 COMMON_FLAGS = BIN_DIR='$(BIN_DIR)' CONFIG_DIR='$(CONFIG_DIR)' LOG_DIR='$(LOG_DIR)' PLUGINS_DIR='$(PLUGINS_DIR)'
 
 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
 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
-libs    = -pthread -lz
+libs    = -pthread
 
 ifdef debug
 COMMON_FLAGS += debug=1
@@ -48,6 +52,12 @@ ifdef NETDATA_NO_DAEMON
 CFLAGS += -DNETDATA_NO_DAEMON=1
 endif
 
+ifdef NETDATA_WITHOUT_ZLIB
+CFLAGS += -DNETDATA_WITHOUT_ZLIB=1
+else
+libs += -lz
+endif
+
 # nfacct requires root access, so we prefer it as a plugin.d external plugin
 ifdef INTERNAL_PLUGIN_NFACCT
 CFLAGS += -DINTERNAL_PLUGIN_NFACCT=1
index 02439c3c0b70a1e4b63e979ff70ae26977bfbbfd..560791753b8392552dbb92a1995f4744241f7fd4 100755 (executable)
@@ -1,6 +1,7 @@
 // enable strcasestr()
 #define _GNU_SOURCE
 
+#include <unistd.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -224,22 +225,28 @@ void web_client_reset(struct web_client *w)
        struct timeval tv;
        gettimeofday(&tv, NULL);
 
-       long sent = w->zoutput?(long)w->zstream.total_out:((w->mode == WEB_CLIENT_MODE_FILECOPY)?w->data->rbytes:w->data->bytes);
+       long sent = (w->mode == WEB_CLIENT_MODE_FILECOPY)?w->data->rbytes:w->data->bytes;
+
+#ifndef NETDATA_WITHOUT_ZLIB
+       if(likely(w->zoutput)) sent = (long)w->zstream.total_out;
+#endif
+
        long size = (w->mode == WEB_CLIENT_MODE_FILECOPY)?w->data->rbytes:w->data->bytes;
 
-       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'",
-               w->id,
-               sent, size, -((size>0)?((float)(size-sent)/(float)size * 100.0):0.0),
-               (float)usecdiff(&w->tv_ready, &w->tv_in) / 1000.0,
-               (float)usecdiff(&tv, &w->tv_ready) / 1000.0,
-               (float)usecdiff(&tv, &w->tv_in) / 1000.0,
-               (w->mode == WEB_CLIENT_MODE_FILECOPY)?"filecopy":"data",
-               w->last_url
+       if(likely(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'",
+                       w->id,
+                       sent, size, -((size>0)?((float)(size-sent)/(float)size * 100.0):0.0),
+                       (float)usecdiff(&w->tv_ready, &w->tv_in) / 1000.0,
+                       (float)usecdiff(&tv, &w->tv_ready) / 1000.0,
+                       (float)usecdiff(&tv, &w->tv_in) / 1000.0,
+                       (w->mode == WEB_CLIENT_MODE_FILECOPY)?"filecopy":"data",
+                                       w->last_url
                );
 
        debug(D_WEB_CLIENT, "%llu: Reseting client.", w->id);
 
-       if(w->mode == WEB_CLIENT_MODE_FILECOPY) {
+       if(unlikely(w->mode == WEB_CLIENT_MODE_FILECOPY)) {
                debug(D_WEB_CLIENT, "%llu: Closing filecopy input file.", w->id);
                close(w->ifd);
                w->ifd = w->ofd;
@@ -260,11 +267,13 @@ void web_client_reset(struct web_client *w)
        w->wait_receive = 1;
        w->wait_send = 0;
 
+       w->zoutput = 0;
+
        // if we had enabled compression, release it
+#ifndef NETDATA_WITHOUT_ZLIB
        if(w->zinitialized) {
                debug(D_DEFLATE, "%llu: Reseting compression.", w->id);
                deflateEnd(&w->zstream);
-               w->zoutput = 0;
                w->zsent = 0;
                w->zhave = 0;
                w->zstream.avail_in = 0;
@@ -273,8 +282,10 @@ void web_client_reset(struct web_client *w)
                w->zstream.total_out = 0;
                w->zinitialized = 0;
        }
+#endif // NETDATA_WITHOUT_ZLIB
 }
 
+#ifndef NETDATA_WITHOUT_ZLIB
 void web_client_enable_deflate(struct web_client *w) {
        if(w->zinitialized == 1) {
                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) {
 
        debug(D_DEFLATE, "%llu: Initialized compression.", w->id);
 }
+#endif // NETDATA_WITHOUT_ZLIB
 
 int web_client_data_request(struct web_client *w, char *url, int datasource_type)
 {
@@ -543,9 +555,11 @@ void web_client_process(struct web_client *w) {
                if(strcasestr(w->data->buffer, "Connection: keep-alive")) w->keepalive = 1;
                else w->keepalive = 0;
 
+#ifndef NETDATA_WITHOUT_ZLIB
                // check if the client accepts deflate
                if(web_enable_gzip && strstr(w->data->buffer, "gzip"))
                        web_client_enable_deflate(w);
+#endif // NETDATA_WITHOUT_ZLIB
 
                int datasource_type = DATASOURCE_GOOGLE_JSONP;
                //if(strstr(w->data->buffer, "X-DataSource-Auth"))
@@ -974,6 +988,7 @@ long web_client_send_chunk_finalize(struct web_client *w)
        return bytes;
 }
 
+#ifndef NETDATA_WITHOUT_ZLIB
 long web_client_send_deflate(struct web_client *w)
 {
        long bytes = 0, t = 0;
@@ -1074,14 +1089,17 @@ long web_client_send_deflate(struct web_client *w)
 
        return(bytes);
 }
+#endif // NETDATA_WITHOUT_ZLIB
 
 long web_client_send(struct web_client *w)
 {
-       if(w->zoutput) return web_client_send_deflate(w);
+#ifndef NETDATA_WITHOUT_ZLIB
+       if(likely(w->zoutput)) return web_client_send_deflate(w);
+#endif // NETDATA_WITHOUT_ZLIB
 
        long bytes;
 
-       if(w->data->bytes - w->data->sent == 0) {
+       if(unlikely(w->data->bytes - w->data->sent == 0)) {
                // there is nothing to send
 
                debug(D_WEB_CLIENT, "%llu: Out of output data.", w->id);
@@ -1097,7 +1115,7 @@ long web_client_send(struct web_client *w)
                        return(0);
                }
 
-               if(w->keepalive == 0) {
+               if(unlikely(w->keepalive == 0)) {
                        debug(D_WEB_CLIENT, "%llu: Closing (keep-alive is not enabled). %ld bytes sent.", w->id, w->data->sent);
                        errno = 0;
                        return(-1);
@@ -1109,14 +1127,13 @@ long web_client_send(struct web_client *w)
        }
 
        bytes = send(w->ofd, &w->data->buffer[w->data->sent], w->data->bytes - w->data->sent, MSG_DONTWAIT);
-       if(bytes > 0) {
+       if(likely(bytes > 0)) {
                w->data->sent += bytes;
                debug(D_WEB_CLIENT, "%llu: Sent %d bytes.", w->id, bytes);
        }
-       else if(bytes == 0) debug(D_WEB_CLIENT, "%llu: Did not send any bytes to the client.", w->id);
+       else if(likely(bytes == 0)) debug(D_WEB_CLIENT, "%llu: Did not send any bytes to the client.", w->id);
        else debug(D_WEB_CLIENT, "%llu: Failed to send data to client. Reason: %s", w->id, strerror(errno));
 
-
        return(bytes);
 }
 
@@ -1128,12 +1145,12 @@ long web_client_receive(struct web_client *w)
        long left = w->data->size - w->data->bytes;
        long bytes;
 
-       if(w->mode == WEB_CLIENT_MODE_FILECOPY)
+       if(unlikely(w->mode == WEB_CLIENT_MODE_FILECOPY))
                bytes = read(w->ifd, &w->data->buffer[w->data->bytes], (left-1));
        else
                bytes = recv(w->ifd, &w->data->buffer[w->data->bytes], left-1, MSG_DONTWAIT);
 
-       if(bytes > 0) {
+       if(likely(bytes > 0)) {
                int old = w->data->bytes;
                w->data->bytes += bytes;
                w->data->buffer[w->data->bytes] = '\0';
@@ -1146,7 +1163,7 @@ long web_client_receive(struct web_client *w)
                        if(w->data->rbytes && w->data->bytes >= w->data->rbytes) w->wait_receive = 0;
                }
        }
-       else if(bytes == 0) {
+       else if(likely(bytes == 0)) {
                debug(D_WEB_CLIENT, "%llu: Out of input data.", w->id);
 
                // if we cannot read, it means we have an error on input.
index 68502a6da4274470203c1924fbefda564dfc3da3..534fcd539cd8a2d77b68b5b913b2e80e6361119f 100755 (executable)
@@ -1,4 +1,8 @@
+
+#ifndef NETDATA_WITHOUT_ZLIB
 #include <zlib.h>
+#endif
+
 #include <sys/time.h>
 #include <string.h>
 #include <sys/socket.h>
@@ -68,11 +72,13 @@ struct web_client {
        struct web_buffer *data;
 
        int zoutput;                                    // if set to 1, web_client_send() will send compressed data
+#ifndef NETDATA_WITHOUT_ZLIB
        z_stream zstream;                               // zlib stream for sending compressed output to client
        Bytef zbuffer[ZLIB_CHUNK];              // temporary buffer for storing compressed output
        long zsent;                                     // the compressed bytes we have sent to the client
        long zhave;                                     // the compressed bytes that we have to send
        int zinitialized;
+#endif
 
        int wait_receive;
        int wait_send;
index c8e1dd7e549aa8b9a85ecb738e7ff56c6f372399..0b8b6e86918bdaaf957b60f1698b188ea95294ed 100755 (executable)
@@ -1,6 +1,7 @@
 // enable strcasestr()
 #define _GNU_SOURCE
 
+#include <unistd.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/socket.h>