about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-05-16 20:05:12 +0000
committerEric Wong <normalperson@yhbt.net>2011-05-16 20:05:12 +0000
commitf9de85b9a35c9f95b390249ea855858c5e4a3ae2 (patch)
tree0626bc1ce9e1a4152b8dd9e460077b2f20eb3bf3
parent49b60d6f67a94560a802c6ff80c16c92093de877 (diff)
Just close the epoll descriptor, since the sleepy_penguin
epoll_wait wrapper may not return EINTR in the future.
-rw-r--r--lib/rainbows.rb6
-rw-r--r--lib/rainbows/epoll.rb1
-rw-r--r--lib/rainbows/xepoll.rb1
-rw-r--r--lib/rainbows/xepoll_thread_pool/client.rb1
-rw-r--r--lib/rainbows/xepoll_thread_spawn/client.rb1
5 files changed, 10 insertions, 0 deletions
diff --git a/lib/rainbows.rb b/lib/rainbows.rb
index 18c9b06..ff80c08 100644
--- a/lib/rainbows.rb
+++ b/lib/rainbows.rb
@@ -87,6 +87,11 @@ module Rainbows
   @cur = 0
   @tick_mod = 0
   @expire = nil
+  @at_quit = []
+
+  def self.at_quit(&block)
+    @at_quit << block
+  end
 
   def self.tick
     @tick_io.chmod(@tick_mod = 0 == @tick_mod ? 1 : 0)
@@ -104,6 +109,7 @@ module Rainbows
       Rainbows::HttpParser.quit
       @expire = Time.now + (@server.timeout * 2.0)
       Unicorn::HttpServer::LISTENERS.each { |s| s.close rescue nil }.clear
+      @at_quit.each { |task| task.call }
     end
     false
   end
diff --git a/lib/rainbows/epoll.rb b/lib/rainbows/epoll.rb
index 8f3d020..3a23d51 100644
--- a/lib/rainbows/epoll.rb
+++ b/lib/rainbows/epoll.rb
@@ -46,6 +46,7 @@ module Rainbows::Epoll
   def init_worker_process(worker)
     super
     Rainbows::Epoll.const_set :EP, SleepyPenguin::Epoll.new
+    Rainbows.at_quit { Rainbows::Epoll::EP.close }
     Rainbows::Client.__send__ :include, Client
   end
 
diff --git a/lib/rainbows/xepoll.rb b/lib/rainbows/xepoll.rb
index 2b38900..ef7ea05 100644
--- a/lib/rainbows/xepoll.rb
+++ b/lib/rainbows/xepoll.rb
@@ -14,6 +14,7 @@ module Rainbows::XEpoll
   def init_worker_process(worker)
     super
     Rainbows::Epoll.const_set :EP, SleepyPenguin::Epoll.new
+    Rainbows.at_quit { Rainbows::Epoll::EP.close }
     Rainbows::Client.__send__ :include, Client
   end
 
diff --git a/lib/rainbows/xepoll_thread_pool/client.rb b/lib/rainbows/xepoll_thread_pool/client.rb
index f871e56..b33998d 100644
--- a/lib/rainbows/xepoll_thread_pool/client.rb
+++ b/lib/rainbows/xepoll_thread_pool/client.rb
@@ -37,6 +37,7 @@ module Rainbows::XEpollThreadPool::Client
 
   ep = SleepyPenguin::Epoll
   EP = ep.new
+  Rainbows.at_quit { EP.close }
   IN = ep::IN | ep::ET | ep::ONESHOT
   KATO = {}
   KATO.compare_by_identity if KATO.respond_to?(:compare_by_identity)
diff --git a/lib/rainbows/xepoll_thread_spawn/client.rb b/lib/rainbows/xepoll_thread_spawn/client.rb
index f8fc191..2ab64d2 100644
--- a/lib/rainbows/xepoll_thread_spawn/client.rb
+++ b/lib/rainbows/xepoll_thread_spawn/client.rb
@@ -26,6 +26,7 @@ module Rainbows::XEpollThreadSpawn::Client
 
   ep = SleepyPenguin::Epoll
   EP = ep.new
+  Rainbows.at_quit { EP.close }
   IN = ep::IN | ep::ET | ep::ONESHOT
   KATO = {}
   KATO.compare_by_identity if KATO.respond_to?(:compare_by_identity)