collectd-tg: Fix sleep interval.
[collectd.git] / src / collectd-tg.c
index 23257fd..273265c 100644 (file)
@@ -46,7 +46,6 @@
 
 #include "libcollectdclient/collectd/client.h"
 #include "libcollectdclient/collectd/network.h"
-#include "libcollectdclient/collectd/network_buffer.h"
 
 #define DEF_NUM_HOSTS    1000
 #define DEF_NUM_PLUGINS    20
@@ -338,7 +337,6 @@ static int read_options (int argc, char **argv) /* {{{ */
 
 int main (int argc, char **argv) /* {{{ */
 {
-  int i;
   double last_time;
   int values_sent = 0;
 
@@ -384,7 +382,7 @@ int main (int argc, char **argv) /* {{{ */
 
   fprintf (stdout, "Creating %i values ... ", conf_num_values);
   fflush (stdout);
-  for (i = 0; i < conf_num_values; i++)
+  for (int i = 0; i < conf_num_values; i++)
   {
     lcc_value_list_t *vl;
 
@@ -416,11 +414,11 @@ int main (int argc, char **argv) /* {{{ */
 
       while (now < vl->time)
       {
-        /* 1 / 100 second */
-        struct timespec ts = { 0, 10000000 };
-
-        ts.tv_sec = (time_t) now;
-        ts.tv_nsec = (long) ((now - ((double) ts.tv_sec)) * 1e9);
+        double diff = vl->time - now;
+        struct timespec ts = {
+          .tv_sec = (time_t) diff,
+        };
+        ts.tv_nsec = (long) ((diff - ((double) ts.tv_sec)) * 1e9);
 
         nanosleep (&ts, /* remaining = */ NULL);
         now = dtime ();
@@ -451,7 +449,6 @@ int main (int argc, char **argv) /* {{{ */
 
   lcc_network_destroy (net);
   exit (EXIT_SUCCESS);
-  return (0);
 } /* }}} int main */
 
 /* vim: set sw=2 sts=2 et fdm=marker : */