about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-10-11 02:09:52 -0700
committerEric Wong <normalperson@yhbt.net>2009-10-11 02:12:50 -0700
commit36869925dbd73533a5b71ab0dfe838b371f420e1 (patch)
tree7d686c75ce0f471a669ed33f6b4b28a7a82de8f7
parent7e7de6f43ca9c1e8d8ee2eae56578e31e22082e6 (diff)
downloadrainbows-36869925dbd73533a5b71ab0dfe838b371f420e1.tar.gz
-rw-r--r--lib/rainbows/revactor.rb22
1 files changed, 10 insertions, 12 deletions
diff --git a/lib/rainbows/revactor.rb b/lib/rainbows/revactor.rb
index 1b954b4..e0b98c1 100644
--- a/lib/rainbows/revactor.rb
+++ b/lib/rainbows/revactor.rb
@@ -74,19 +74,17 @@ module Rainbows
     # for connections and doesn't die until the parent dies (or is
     # given a INT, QUIT, or TERM signal)
     def worker_loop(worker)
-      ppid = master_pid
       init_worker_process(worker)
-      alive = worker.tmp # tmp is our lifeline to the master process
 
       root = Actor.current
       root.trap_exit = true
 
       limit = worker_connections
-      listeners = revactorize_listeners
-      logger.info "worker=#{worker.nr} ready with Revactor"
+      revactorize_listeners!
       clients = 0
+      alive = worker.tmp
 
-      listeners.map! do |s|
+      listeners = LISTENERS.map do |s|
         Actor.spawn(s) do |l|
           begin
             while clients >= limit
@@ -109,10 +107,9 @@ module Rainbows
       begin
         Actor.receive do |filter|
           filter.after(1) do
-            if alive
-              alive.chmod(m = 0 == m ? 1 : 0)
-              listeners.each { |l| alive = false if l.dead? }
-              ppid == Process.ppid or alive = false
+            alive.chmod(m = 0 == m ? 1 : 0)
+            if listeners.any? { |l| l.dead? } || master_pid != Process.ppid
+              alive = false
             end
           end
           filter.when(Case[:exit, Actor, Object]) do |_,actor,_|
@@ -136,8 +133,8 @@ module Rainbows
       client.close rescue nil
     end
 
-    def revactorize_listeners
-      LISTENERS.map do |s|
+    def revactorize_listeners!
+      LISTENERS.map! do |s|
         if TCPServer === s
           ::Revactor::TCP.listen(s, nil)
         elsif defined?(::Revactor::UNIX) && UNIXServer === s
@@ -146,7 +143,8 @@ module Rainbows
           logger.error "your version of Revactor can't handle #{s.inspect}"
           nil
         end
-      end.compact
+      end
+      LISTENERS.compact!
     end
 
   end