AMQP plugin: Support sub-second sleep intervals.
[collectd.git] / src / amqp.c
index 55eba67..be1f709 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;
         }