summaryrefslogtreecommitdiff
blob: 12b8fb14e67169b8f8728aed4534f98476f57783 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2011-10-14 Israel G. Lugo <israel.lugo@lugosys.com>

* Fix delay_loop() for delays of 1s and greater. Was causing breakage when a
low bandwidth limit was specified.


Index: compat/delay.cpp
===================================================================
--- compat/delay.cpp	(revision 81)
+++ compat/delay.cpp	(working copy)
@@ -63,8 +63,9 @@ void delay_loop(unsigned long usec)
 {
     struct timespec requested, remaining;
 
-    requested.tv_sec  = 0;
-    requested.tv_nsec = usec * 1000L;
+    /* convert to seconds; nanosleep requires 0 <= tv_nsec <= 999999999 */
+    requested.tv_sec  = usec / 1000000UL;
+    requested.tv_nsec = (usec % 1000000UL) * 1000UL;
 
     while (nanosleep(&requested, &remaining) == -1)
         if (errno == EINTR)