Code

AMQP plugin: Support sub-second sleep intervals.
authorFlorian Forster <octo@collectd.org>
Sun, 19 Feb 2012 11:51:09 +0000 (12:51 +0100)
committerFlorian Forster <octo@collectd.org>
Sun, 19 Feb 2012 11:51:09 +0000 (12:51 +0100)
Change-Id: I9afcd8d17f1251b0765dfbdae5ed8581b73b15fe

src/amqp.c

index 55eba670bc712f195ee7b6117f8dc98d72db5d8a..be1f709e120181efdf7ce8181c4f9032f02047ed 100644 (file)
@@ -550,21 +550,25 @@ static void *camqp_subscribe_thread (void *user_data) /* {{{ */
         status = camqp_connect (conf);
         if (status != 0)
         {
+            struct timespec ts_interval;
             ERROR ("amqp plugin: camqp_connect failed. "
-                    "Will sleep for %u seconds.",
-                    (unsigned int) CDTIME_T_TO_TIME_T (interval_g));
-            sleep ((unsigned int) CDTIME_T_TO_TIME_T (interval_g));
+                    "Will sleep for %.3f seconds.",
+                    CDTIME_T_TO_DOUBLE (interval_g));
+            CDTIME_T_TO_TIMESPEC (interval_g, &ts_interval);
+            nanosleep (&ts_interval, /* remaining = */ NULL);
             continue;
         }
 
         status = amqp_simple_wait_frame (conf->connection, &frame);
         if (status < 0)
         {
+            struct timespec ts_interval;
             ERROR ("amqp plugin: amqp_simple_wait_frame failed. "
-                    "Will sleep for %u seconds.",
-                    (unsigned int) CDTIME_T_TO_TIME_T (interval_g));
+                    "Will sleep for %.3f seconds.",
+                    CDTIME_T_TO_DOUBLE (interval_g));
             camqp_close_connection (conf);
-            sleep ((unsigned int) CDTIME_T_TO_TIME_T (interval_g));
+            CDTIME_T_TO_TIMESPEC (interval_g, &ts_interval);
+            nanosleep (&ts_interval, /* remaining = */ NULL);
             continue;
         }