about summary refs log tree commit homepage
path: root/lib/rainbows/rev.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-10-18 20:04:57 -0700
committerEric Wong <normalperson@yhbt.net>2009-10-18 21:23:34 -0700
commit87a9cf757bbef7bb54a187933c1bc61ed1f05583 (patch)
tree879ccc857bacf7785c64b15f033ba140d7e162d8 /lib/rainbows/rev.rb
parent1a1335fe5b1894848b48a233c9f6a80634329b40 (diff)
downloadrainbows-87a9cf757bbef7bb54a187933c1bc61ed1f05583.tar.gz
Oops, looks like they were never implemented at all.
Diffstat (limited to 'lib/rainbows/rev.rb')
-rw-r--r--lib/rainbows/rev.rb35
1 files changed, 20 insertions, 15 deletions
diff --git a/lib/rainbows/rev.rb b/lib/rainbows/rev.rb
index 19e721a..fd25200 100644
--- a/lib/rainbows/rev.rb
+++ b/lib/rainbows/rev.rb
@@ -156,26 +156,31 @@ module Rainbows
 
     end
 
+    # This timer handles the fchmod heartbeat to prevent our master
+    # from killing us.
+    class Heartbeat < ::Rev::TimerWatcher
+      G = Rainbows::G
+
+      def initialize(tmp)
+        @m, @tmp = 0, tmp
+        super(1, true)
+      end
+
+      def on_timer
+        @tmp.chmod(@m = 0 == @m ? 1 : 0)
+        exit if (! G.alive && G.cur <= 0)
+      end
+    end
+
     # runs inside each forked worker, this sits around and waits
     # for connections and doesn't die until the parent dies (or is
     # given a INT, QUIT, or TERM signal)
     def worker_loop(worker)
       init_worker_process(worker)
-      graceful_waiter = nil
-      trap(:QUIT) do
-        G.alive = false
-        LISTENERS.map! { |s| s.close rescue nil }
-        # Rev may get stuck in a loop with no events possible, spawn a new
-        # thread to join on graceful exits when our client count goes to zero
-        graceful_waiter = Thread.new {
-          sleep(0.1) while G.cur > 0
-          exit
-        }
-      end
-
-      LISTENERS.map! { |s| Server.new(s).attach(::Rev::Loop.default) }
-      ::Rev::Loop.default.run
-      graceful_waiter.join(timeout * 2.0)
+      rloop = ::Rev::Loop.default
+      Heartbeat.new(worker.tmp).attach(rloop)
+      LISTENERS.map! { |s| Server.new(s).attach(rloop) }
+      rloop.run
     end
 
   end