projects
/
collectd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
635bcdf
)
http plugin: Implement a `flush' callback.
author
Florian Forster
<octo@leeloo.lan.home.verplant.org>
Fri, 21 Aug 2009 09:34:39 +0000
(11:34 +0200)
committer
Florian Forster
<octo@leeloo.lan.home.verplant.org>
Fri, 21 Aug 2009 09:34:39 +0000
(11:34 +0200)
src/http.c
patch
|
blob
|
history
diff --git
a/src/http.c
b/src/http.c
index
8027220
..
587e314
100644
(file)
--- a/
src/http.c
+++ b/
src/http.c
@@
-55,6
+55,7
@@
char curl_errbuf[CURL_ERROR_SIZE];
static char send_buffer[SEND_BUFFER_SIZE];
static size_t send_buffer_free;
static size_t send_buffer_fill;
static char send_buffer[SEND_BUFFER_SIZE];
static size_t send_buffer_free;
static size_t send_buffer_fill;
+static time_t send_buffer_init_time;
static pthread_mutex_t send_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t send_lock = PTHREAD_MUTEX_INITIALIZER;
@@
-226,6
+227,7
@@
static void http_init_buffer (void) /* {{{ */
memset (send_buffer, 0, sizeof (send_buffer));
send_buffer_free = sizeof (send_buffer);
send_buffer_fill = 0;
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) /* {{{ */
} /* }}} http_init_buffer */
static int http_send_buffer (char *buffer) /* {{{ */
@@
-242,16
+244,40
@@
static int http_send_buffer (char *buffer) /* {{{ */
return (status);
} /* }}} http_send_buffer */
return (status);
} /* }}} http_send_buffer */
-static int http_flush_
buffer (void
) /* {{{ */
+static int http_flush_
nolock (int timeout
) /* {{{ */
{
{
- int status = 0;
- DEBUG ("http plugin: flushing buffer:\n%s", send_buffer);
+ int status;
+
+ DEBUG ("http plugin: http_flush_nolock: timeout = %i; "
+ "send_buffer =\n %s", timeout, send_buffer);
+
+ if (timeout > 0)
+ {
+ time_t now;
+
+ now = time (NULL);
+ if ((send_buffer_init_time + timeout) > now)
+ return (0);
+ }
status = http_send_buffer (send_buffer);
http_init_buffer ();
return (status);
status = http_send_buffer (send_buffer);
http_init_buffer ();
return (status);
-} /* }}} http_flush_buffer */
+} /* }}} http_flush_nolock */
+
+static int http_flush (int timeout, /* {{{ */
+ const char *identifier __attribute__((unused)),
+ user_data_t *user_data __attribute__((unused)))
+{
+ int status;
+
+ pthread_mutex_lock (&send_lock);
+ status = http_flush_nolock (timeout);
+ pthread_mutex_unlock (&send_lock);
+
+ return (status);
+} /* }}} int http_flush */
static int http_write_command (const data_set_t *ds, const value_list_t *vl) /* {{{ */
{
static int http_write_command (const data_set_t *ds, const value_list_t *vl) /* {{{ */
{
@@
-297,7
+323,7
@@
static int http_write_command (const data_set_t *ds, const value_list_t *vl) /*
/* Check if we have enough space for this command. */
if (command_len >= send_buffer_free)
{
/* Check if we have enough space for this command. */
if (command_len >= send_buffer_free)
{
- status = http_flush_
buffer(
);
+ status = http_flush_
nolock (/* timeout = */ -1
);
if (status != 0)
{
pthread_mutex_unlock (&send_lock);
if (status != 0)
{
pthread_mutex_unlock (&send_lock);
@@
-329,7
+355,7
@@
static int http_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */
static int http_shutdown (void) /* {{{ */
{
static int http_shutdown (void) /* {{{ */
{
- http_flush_
buffer(
);
+ http_flush_
nolock (/* timeout = */ -1
);
curl_easy_cleanup(curl);
return (0);
}
curl_easy_cleanup(curl);
return (0);
}
@@
-340,6
+366,7
@@
void module_register (void) /* {{{ */
plugin_register_config ("http", http_config,
config_keys, config_keys_num);
plugin_register_write ("http", http_write, /* user_data = */ NULL);
plugin_register_config ("http", http_config,
config_keys, config_keys_num);
plugin_register_write ("http", http_write, /* user_data = */ NULL);
+ plugin_register_flush ("http", http_flush, /* user_data = */ NULL);
plugin_register_shutdown("http", http_shutdown);
} /* }}} void module_register */
plugin_register_shutdown("http", http_shutdown);
} /* }}} void module_register */