From: Florian Forster Date: Fri, 21 Aug 2009 10:45:54 +0000 (+0200) Subject: http plugin: Small fixes for the buffer handling. X-Git-Tag: collectd-4.8.0~26^2~5 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=55b1cf691749105608964c051fc2936711cf23db;p=collectd.git http plugin: Small fixes for the buffer handling. Don't actually send anything when the buffer is empty. Initialize the buffer in the ‘init’ function. --- diff --git a/src/http.c b/src/http.c index 587e3143..392f8539 100644 --- a/src/http.c +++ b/src/http.c @@ -59,6 +59,14 @@ static time_t send_buffer_init_time; static pthread_mutex_t send_lock = PTHREAD_MUTEX_INITIALIZER; +static void http_init_buffer (void) /* {{{ */ +{ + memset (send_buffer, 0, sizeof (send_buffer)); + send_buffer_free = sizeof (send_buffer); + send_buffer_fill = 0; + send_buffer_init_time = time (NULL); +} /* }}} http_init_buffer */ + static int http_init(void) /* {{{ */ { @@ -102,6 +110,8 @@ static int http_init(void) /* {{{ */ curl_easy_setopt (curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); } + http_init_buffer (); + return (0); } /* }}} */ @@ -222,14 +232,6 @@ static int http_config (const char *key, const char *value) /* {{{ */ return (0); } /* }}} int http_config */ -static void http_init_buffer (void) /* {{{ */ -{ - memset (send_buffer, 0, sizeof (send_buffer)); - send_buffer_free = sizeof (send_buffer); - send_buffer_fill = 0; - send_buffer_init_time = time (NULL); -} /* }}} http_init_buffer */ - static int http_send_buffer (char *buffer) /* {{{ */ { int status = 0; @@ -260,6 +262,12 @@ static int http_flush_nolock (int timeout) /* {{{ */ return (0); } + if (send_buffer_fill <= 0) + { + send_buffer_init_time = time (NULL); + return (0); + } + status = http_send_buffer (send_buffer); http_init_buffer (); @@ -358,7 +366,7 @@ static int http_shutdown (void) /* {{{ */ http_flush_nolock (/* timeout = */ -1); curl_easy_cleanup(curl); return (0); -} +} /* }}} int http_shutdown */ void module_register (void) /* {{{ */ {