[or-cvs] r17691: {tor} Why were we using gettimeofday() in second_elapsed_callback? (tor/trunk/src/or)

nickm at seul.org nickm at seul.org
Thu Dec 18 17:19:29 UTC 2008


Author: nickm
Date: 2008-12-18 12:19:23 -0500 (Thu, 18 Dec 2008)
New Revision: 17691

Modified:
   tor/trunk/src/or/main.c
Log:
Why were we using gettimeofday() in second_elapsed_callback?  We were only ever looking at the tv_sec field.

Modified: tor/trunk/src/or/main.c
===================================================================
--- tor/trunk/src/or/main.c	2008-12-18 17:19:04 UTC (rev 17690)
+++ tor/trunk/src/or/main.c	2008-12-18 17:19:23 UTC (rev 17691)
@@ -1173,7 +1173,7 @@
    * time against a bunch of timeouts every second. */
   static struct timeval one_second;
   static long current_second = 0;
-  struct timeval now;
+  time_t now;
   size_t bytes_written;
   size_t bytes_read;
   int seconds_elapsed;
@@ -1191,13 +1191,13 @@
   n_libevent_errors = 0;
 
   /* log_fn(LOG_NOTICE, "Tick."); */
-  tor_gettimeofday(&now);
-  update_approx_time(now.tv_sec);
+  now = time(NULL);
+  update_approx_time(now);
 
   /* the second has rolled over. check more stuff. */
   bytes_written = stats_prev_global_write_bucket - global_write_bucket;
   bytes_read = stats_prev_global_read_bucket - global_read_bucket;
-  seconds_elapsed = current_second ? (int)(now.tv_sec - current_second) : 0;
+  seconds_elapsed = current_second ? (int)(now - current_second) : 0;
   stats_n_bytes_read += bytes_read;
   stats_n_bytes_written += bytes_written;
   if (accounting_is_enabled(options) && seconds_elapsed >= 0)
@@ -1206,7 +1206,7 @@
   control_event_stream_bandwidth_used();
 
   if (seconds_elapsed > 0)
-    connection_bucket_refill(seconds_elapsed, now.tv_sec);
+    connection_bucket_refill(seconds_elapsed, now);
   stats_prev_global_read_bucket = global_read_bucket;
   stats_prev_global_write_bucket = global_write_bucket;
 
@@ -1243,9 +1243,9 @@
   } else if (seconds_elapsed > 0)
     stats_n_seconds_working += seconds_elapsed;
 
-  run_scheduled_events(now.tv_sec);
+  run_scheduled_events(now);
 
-  current_second = now.tv_sec; /* remember which second it is, for next time */
+  current_second = now; /* remember which second it is, for next time */
 
 #if 0
   if (current_second % 300 == 0) {



More information about the tor-commits mailing list