[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/release-0.2.6] Extract main part of main loop into a separate function



commit b78803f9f543c83bf50d0751eb160e80ed602eae
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Sat Mar 14 14:24:18 2015 -0400

    Extract main part of main loop into a separate function
    
    For 15176; Shadow would like this.
    
    Based on a patch by Rob Jansen, but revised to have a minimal-sized diff.
---
 changes/ticket15176 |    3 +++
 src/or/main.c       |   23 ++++++++++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/changes/ticket15176 b/changes/ticket15176
new file mode 100644
index 0000000..6d12723
--- /dev/null
+++ b/changes/ticket15176
@@ -0,0 +1,3 @@
+  o Code simplification and refactoring:
+    - Refactor main loop to extract the 'loop' part.  This makes it easier
+      to run Tor under Shadow. Closes ticket 15176.
diff --git a/src/or/main.c b/src/or/main.c
index bc89458..f5bca4e 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -97,6 +97,7 @@ static void second_elapsed_callback(periodic_timer_t *timer, void *args);
 static int conn_close_if_marked(int i);
 static void connection_start_reading_from_linked_conn(connection_t *conn);
 static int connection_should_read_from_linked_conn(connection_t *conn);
+static int run_main_loop_until_done(void);
 
 /********* START VARIABLES **********/
 
@@ -1955,7 +1956,6 @@ do_hup(void)
 int
 do_main_loop(void)
 {
-  int loop_result;
   time_t now;
 
   /* initialize dns resolve map, spawn workers if needed */
@@ -2084,7 +2084,14 @@ do_main_loop(void)
   }
 #endif
 
-  for (;;) {
+  return run_main_loop_until_done();
+}
+
+static int
+run_main_loop_once(void)
+{
+  int loop_result;
+  if (1) {
     if (nt_service_is_stopping())
       return 0;
 
@@ -2125,10 +2132,20 @@ do_main_loop(void)
         log_debug(LD_NET,"libevent call interrupted.");
         /* You can't trust the results of this poll(). Go back to the
          * top of the big for loop. */
-        continue;
+        return 1;
       }
     }
   }
+  return 1;
+}
+
+static int
+run_main_loop_until_done(void)
+{
+ int loop_result = 1;
+ while ((loop_result = run_main_loop_once()) == 1)
+   continue;
+ return loop_result;
 }
 
 #ifndef _WIN32 /* Only called when we're willing to use signals */



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits