summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 979b0fa)
raw | patch | inline | side by side (parent: 979b0fa)
author | Manuel Luis Sanmartín Rozada <manuel.luis@gmail.com> | |
Sun, 31 May 2015 20:46:11 +0000 (22:46 +0200) | ||
committer | Manuel Luis Sanmartín Rozada <manuel.luis@gmail.com> | |
Sun, 31 May 2015 20:46:11 +0000 (22:46 +0200) |
src/network.c | patch | blob | history |
diff --git a/src/network.c b/src/network.c
index 551bd5cceea9bc07aba71720ea1d79cdda5226dd..e58d1dc589f3530a1c4790103acaf95e7789b20d 100644 (file)
--- a/src/network.c
+++ b/src/network.c
static char *send_buffer;
static char *send_buffer_ptr;
static int send_buffer_fill;
+static cdtime_t send_buffer_last_update;
static value_list_t send_buffer_vl = VALUE_LIST_STATIC;
static pthread_mutex_t send_buffer_lock = PTHREAD_MUTEX_INITIALIZER;
memset (send_buffer, 0, network_config_packet_size);
send_buffer_ptr = send_buffer;
send_buffer_fill = 0;
+ send_buffer_last_update = 0;
memset (&send_buffer_vl, 0, sizeof (send_buffer_vl));
} /* int network_init_buffer */
/* status == bytes added to the buffer */
send_buffer_fill += status;
send_buffer_ptr += status;
+ send_buffer_last_update = cdtime();
stats_values_sent++;
}
* just send the buffer if `flush' is called - if the requested value was in
* there, good. If not, well, then there is nothing to flush.. -octo
*/
-static int network_flush (__attribute__((unused)) cdtime_t timeout,
+static int network_flush (cdtime_t timeout,
__attribute__((unused)) const char *identifier,
__attribute__((unused)) user_data_t *user_data)
{
pthread_mutex_lock (&send_buffer_lock);
if (send_buffer_fill > 0)
- flush_buffer ();
-
+ {
+ if (timeout > 0)
+ {
+ cdtime_t now = cdtime ();
+ if ((send_buffer_last_update + timeout) > now)
+ {
+ pthread_mutex_unlock (&send_buffer_lock);
+ return (0);
+ }
+ }
+ flush_buffer ();
+ }
pthread_mutex_unlock (&send_buffer_lock);
return (0);