about summary refs log tree commit homepage
path: root/lib/rainbows/base.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-11-06 19:45:17 -0800
committerEric Wong <normalperson@yhbt.net>2009-11-06 19:45:17 -0800
commit1a9a718a3f9a5b582a4a339a9bb9249c2ca392d7 (patch)
tree0c95f2d8fc4de8542f7716832800614e1e7a8872 /lib/rainbows/base.rb
parente1dcadef6ca242e36e99aab19e3e040bf01070f9 (diff)
downloadrainbows-1a9a718a3f9a5b582a4a339a9bb9249c2ca392d7.tar.gz
It turns out neither the EventMachine and Rev classes
checked for master death in its heartbeat mechanism.
Since we managed to forget the same thing twice, we
now have a test case for it and also centralized the
code to remove duplication.
Diffstat (limited to 'lib/rainbows/base.rb')
-rw-r--r--lib/rainbows/base.rb19
1 files changed, 6 insertions, 13 deletions
diff --git a/lib/rainbows/base.rb b/lib/rainbows/base.rb
index 9da148c..9b50d9a 100644
--- a/lib/rainbows/base.rb
+++ b/lib/rainbows/base.rb
@@ -26,20 +26,14 @@ module Rainbows
 
     def init_worker_process(worker)
       super(worker)
-      G.cur = 0
-      G.max = worker_connections
-      G.logger = logger
-      G.app = app
+      G.server = self
+      G.tmp = worker.tmp
 
       # we're don't use the self-pipe mechanism in the Rainbows! worker
       # since we don't defer reopening logs
       HttpServer::SELF_PIPE.each { |x| x.close }.clear
       trap(:USR1) { reopen_worker_logs(worker.nr) rescue nil }
-      trap(:QUIT) do
-        G.alive = false
-        # closing anything we IO.select on will raise EBADF
-        HttpServer::LISTENERS.map! { |s| s.close rescue nil }
-      end
+      trap(:QUIT) { G.quit! }
       [:TERM, :INT].each { |sig| trap(sig) { exit!(0) } } # instant shutdown
       logger.info "Rainbows! #@use worker_connections=#@worker_connections"
     end
@@ -89,13 +83,12 @@ module Rainbows
       logger.error e.backtrace.join("\n")
     end
 
-    def join_threads(threads, worker)
-      Rainbows::G.alive = false
+    def join_threads(threads)
+      G.quit!
       expire = Time.now + (timeout * 2.0)
-      m = 0
       until (threads.delete_if { |thr| ! thr.alive? }).empty?
         threads.each { |thr|
-          worker.tmp.chmod(m = 0 == m ? 1 : 0)
+          G.tick
           thr.join(1)
           break if Time.now >= expire
         }