[2638] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[PATCH 2/3] Move the event loop to owl_select as owl_select_run_loop

daemon@ATHENA.MIT.EDU (David Benjamin)
Sat Sep 18 03:02:48 2010

From: David Benjamin <davidben@MIT.EDU>
To: barnowl-dev@mit.edu
Date: Sat, 18 Sep 2010 03:00:30 -0400
In-Reply-To: <1284793231-20249-1-git-send-email-davidben@mit.edu>

Also adds a function to quit the select loop so that owl_function_quit
needn't exit() directly. main should be allowed to clean up after
itself.
---
 functions.c |    2 +-
 owl.c       |    7 ++-----
 select.c    |   14 ++++++++++++++
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/functions.c b/functions.c
index 8d9d01f..658d78f 100644
--- a/functions.c
+++ b/functions.c
@@ -975,7 +975,7 @@ void owl_function_quit(void)
   tcsetattr(0, TCSAFLUSH, owl_global_get_startup_tio(&g));
 
   owl_function_debugmsg("Quitting Owl");
-  exit(0);
+  owl_select_quit_loop();
 }
 
 void owl_function_calculate_topmsg(int direction)
diff --git a/owl.c b/owl.c
index 5d3b81d..850d09f 100644
--- a/owl.c
+++ b/owl.c
@@ -583,9 +583,6 @@ int main(int argc, char **argv, char **env)
   owl_select_add_pre_select_action(owl_errsignal_pre_select_action, NULL, NULL);
 
   owl_function_debugmsg("startup: entering main loop");
-  /* main loop */
-  while (1) {
-    /* select on FDs we know about. */
-    owl_select();
-  }
+  owl_select_run_loop();
+  return 0;
 }
diff --git a/select.c b/select.c
index f3e0b6e..a6f0ddf 100644
--- a/select.c
+++ b/select.c
@@ -2,6 +2,7 @@
 
 static int dispatch_active = 0;
 static int psa_active = 0;
+static int loop_active = 0;
 
 int _owl_select_timer_cmp(const owl_timer *t1, const owl_timer *t2) {
   return t1->time - t2->time;
@@ -435,3 +436,16 @@ void owl_select(void)
     owl_select_io_dispatch(&r, &w, &e, max_fd);
   }
 }
+
+void owl_select_run_loop(void)
+{
+  loop_active = 1;
+  while (loop_active) {
+    owl_select();
+  }
+}
+
+void owl_select_quit_loop(void)
+{
+  loop_active = 0;
+}
-- 
1.7.2.1.45.gb1c4


home help back first fref pref prev next nref lref last post