added delay loop code
authorAndrew Tridgell <tridge@samba.org>
Fri, 22 Aug 2008 02:25:22 +0000 (12:25 +1000)
committerAndrew Tridgell <tridge@samba.org>
Fri, 22 Aug 2008 02:25:22 +0000 (12:25 +1000)
socklib/sock_sink.c
socklib/socklib.c
socklib/socklib.h

index 576c12d..31a8405 100644 (file)
@@ -49,7 +49,7 @@ static void sender(void)
                        }
                }
                if (delay_per_packet) {
-                       usleep(delay_per_packet);
+                       delay_loop(delay_per_packet);
                }
                total += ret;
                if (end_timer() > 2.0) {
index f8d11ca..7cb9406 100644 (file)
@@ -242,6 +242,18 @@ double end_timer()
               (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
 }
 
+void delay_loop(unsigned usec)
+{
+       struct timeval t1, t2;
+       double t;
+       gettimeofday(&t1,NULL);
+       do {
+               gettimeofday(&t2,NULL);
+               t = ((t2.tv_sec - t1.tv_sec)*1.0e6 + 
+                    (t2.tv_usec - t1.tv_usec));
+       } while (t < usec);
+}
+
 void report_time(uint64_t total)
 {
        printf("%.6g MB/sec\n", (total/(1.0e6))/end_timer());
index 34ab669..88dca8e 100644 (file)
@@ -29,8 +29,5 @@ double end_timer();
 void report_time(uint64_t total);
 void start_timer();
 void set_socket_options(int fd, char *options);
-
-
-
-
+void delay_loop(unsigned usec);