* 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 (int timeout,
- const char __attribute__((unused)) *identifier,
- user_data_t __attribute__((unused)) *user_data)
+static int network_flush (__attribute__((unused)) cdtime_t timeout,
+ __attribute__((unused)) const char *identifier,
+ __attribute__((unused)) user_data_t *user_data)
{
pthread_mutex_lock (&send_buffer_lock);
return (status);
} /* }}} int plugin_write */
-int plugin_flush (const char *plugin, int timeout, const char *identifier)
+int plugin_flush (const char *plugin, cdtime_t timeout, const char *identifier)
{
llentry_t *le;
typedef int (*plugin_read_cb) (user_data_t *);
typedef int (*plugin_write_cb) (const data_set_t *, const value_list_t *,
user_data_t *);
-typedef int (*plugin_flush_cb) (int timeout, const char *identifier,
+typedef int (*plugin_flush_cb) (cdtime_t timeout, const char *identifier,
user_data_t *);
typedef void (*plugin_log_cb) (int severity, const char *message,
user_data_t *);
int plugin_write (const char *plugin,
const data_set_t *ds, const value_list_t *vl);
-int plugin_flush (const char *plugin, int timeout, const char *identifier);
+int plugin_flush (const char *plugin, cdtime_t timeout, const char *identifier);
/*
* The `plugin_register_*' functions are used to make `config', `init',
return (0);
} /* int rrd_queue_dequeue */
-static void rrd_cache_flush (int timeout)
+/* XXX: You must hold "cache_lock" when calling this function! */
+static void rrd_cache_flush (cdtime_t timeout)
{
rrd_cache_t *rc;
- time_t now;
+ cdtime_t now;
char **keys = NULL;
int keys_num = 0;
c_avl_iterator_t *iter;
int i;
- DEBUG ("rrdtool plugin: Flushing cache, timeout = %i", timeout);
+ DEBUG ("rrdtool plugin: Flushing cache, timeout = %.3f",
+ CDTIME_T_TO_DOUBLE (timeout));
- now = time (NULL);
+ now = cdtime ();
+ timeout = TIME_T_TO_CDTIME_T (timeout);
/* Build a list of entries to be flushed */
iter = c_avl_get_iterator (cache);
{
if (rc->flags != FLAG_NONE)
continue;
- else if ((now - rc->first_value) < timeout)
+ /* timeout == 0 => flush everything */
+ else if ((timeout != 0)
+ && ((now - rc->first_value) < timeout))
continue;
else if (rc->values_num > 0)
{
cache_flush_last = now;
} /* void rrd_cache_flush */
-static int rrd_cache_flush_identifier (int timeout, const char *identifier)
+static int rrd_cache_flush_identifier (cdtime_t timeout,
+ const char *identifier)
{
rrd_cache_t *rc;
- time_t now;
+ cdtime_t now;
int status;
char key[2048];
return (0);
}
- now = time (NULL);
+ now = cdtime ();
if (datadir == NULL)
snprintf (key, sizeof (key), "%s.rrd",
return (status);
} /* int rrd_write */
-static int rrd_flush (int timeout, const char *identifier,
- user_data_t __attribute__((unused)) *user_data)
+static int rrd_flush (cdtime_t timeout, const char *identifier,
+ __attribute__((unused)) user_data_t *user_data)
{
pthread_mutex_lock (&cache_lock);
static int rrd_shutdown (void)
{
pthread_mutex_lock (&cache_lock);
- rrd_cache_flush (-1);
+ rrd_cache_flush (0);
pthread_mutex_unlock (&cache_lock);
pthread_mutex_lock (&queue_lock);
return (-1);
}
- cache_flush_last = time (NULL);
- if (cache_timeout < 2)
+ cache_flush_last = cdtime ();
+ if (cache_timeout == 0)
{
- cache_timeout = 0;
cache_flush_timeout = 0;
}
else if (cache_flush_timeout < cache_timeout)
char send_buffer[4096];
size_t send_buffer_free;
size_t send_buffer_fill;
- time_t send_buffer_init_time;
+ cdtime_t send_buffer_init_time;
pthread_mutex_t send_lock;
};
memset (cb->send_buffer, 0, sizeof (cb->send_buffer));
cb->send_buffer_free = sizeof (cb->send_buffer);
cb->send_buffer_fill = 0;
- cb->send_buffer_init_time = time (NULL);
+ cb->send_buffer_init_time = cdtime ();
if (cb->format == WH_FORMAT_JSON)
{
return (0);
} /* }}} int wh_callback_init */
-static int wh_flush_nolock (int timeout, wh_callback_t *cb) /* {{{ */
+static int wh_flush_nolock (cdtime_t timeout, wh_callback_t *cb) /* {{{ */
{
int status;
- DEBUG ("write_http plugin: wh_flush_nolock: timeout = %i; "
+ DEBUG ("write_http plugin: wh_flush_nolock: timeout = %.3f; "
"send_buffer_fill = %zu;",
- timeout, cb->send_buffer_fill);
+ CDTIME_T_TO_DOUBLE (timeout),
+ cb->send_buffer_fill);
+ /* timeout == 0 => flush unconditionally */
if (timeout > 0)
{
- time_t now;
+ cdtime_t now;
- now = time (NULL);
+ now = cdtime ();
if ((cb->send_buffer_init_time + timeout) > now)
return (0);
}
{
if (cb->send_buffer_fill <= 0)
{
- cb->send_buffer_init_time = time (NULL);
+ cb->send_buffer_init_time = cdtime ();
return (0);
}
{
if (cb->send_buffer_fill <= 2)
{
- cb->send_buffer_init_time = time (NULL);
+ cb->send_buffer_init_time = cdtime ();
return (0);
}
return (status);
} /* }}} wh_flush_nolock */
-static int wh_flush (int timeout, /* {{{ */
+static int wh_flush (cdtime_t timeout, /* {{{ */
const char *identifier __attribute__((unused)),
user_data_t *user_data)
{
cb = data;
- wh_flush_nolock (/* timeout = */ -1, cb);
+ wh_flush_nolock (/* timeout = */ 0, cb);
curl_easy_cleanup (cb->curl);
sfree (cb->location);
if (command_len >= cb->send_buffer_free)
{
- status = wh_flush_nolock (/* timeout = */ -1, cb);
+ status = wh_flush_nolock (/* timeout = */ 0, cb);
if (status != 0)
{
pthread_mutex_unlock (&cb->send_lock);
ds, vl, cb->store_rates);
if (status == (-ENOMEM))
{
- status = wh_flush_nolock (/* timeout = */ -1, cb);
+ status = wh_flush_nolock (/* timeout = */ 0, cb);
if (status != 0)
{
wh_reset_buffer (cb);