From 55b1cf691749105608964c051fc2936711cf23db Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Fri, 21 Aug 2009 12:45:54 +0200 Subject: [PATCH] http plugin: Small fixes for the buffer handling. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Don't actually send anything when the buffer is empty. Initialize the buffer in the ‘init’ function. --- src/http.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) 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) /* {{{ */ { -- 2.11.0