about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-05-20 09:19:51 +0000
committerEric Wong <normalperson@yhbt.net>2011-05-20 09:21:18 +0000
commitea6d0eab436c78113f8a61e7fcc34db4117d14c0 (patch)
treed70b0bd67e444997f4122c246ce438dc449242ce
parent90af18f6884857704d72fd6b2bb91718aad72117 (diff)
downloadrainbows-ea6d0eab436c78113f8a61e7fcc34db4117d14c0.tar.gz
In concurrency models long keepalive times are cheap (and thus
more likely to be used), this allows Rainbows! to gracefully
shut down more quickly.
-rw-r--r--lib/rainbows/coolio/heartbeat.rb1
-rw-r--r--lib/rainbows/epoll.rb1
-rw-r--r--lib/rainbows/epoll/client.rb1
-rw-r--r--lib/rainbows/xepoll.rb1
-rw-r--r--lib/rainbows/xepoll_thread_pool/client.rb6
-rw-r--r--lib/rainbows/xepoll_thread_spawn/client.rb6
6 files changed, 12 insertions, 4 deletions
diff --git a/lib/rainbows/coolio/heartbeat.rb b/lib/rainbows/coolio/heartbeat.rb
index f58ed33..3ae9e16 100644
--- a/lib/rainbows/coolio/heartbeat.rb
+++ b/lib/rainbows/coolio/heartbeat.rb
@@ -9,6 +9,7 @@ class Rainbows::Coolio::Heartbeat < Coolio::TimerWatcher
   KATO = Rainbows::Coolio::KATO
   CONN = Rainbows::Coolio::CONN
   Rainbows.config!(self, :keepalive_timeout)
+  Rainbows.at_quit { KATO.each_key { |client| client.timeout? }.clear }
 
   def on_timer
     if (ot = KEEPALIVE_TIMEOUT) >= 0
diff --git a/lib/rainbows/epoll.rb b/lib/rainbows/epoll.rb
index 1a3427e..b9b3d9a 100644
--- a/lib/rainbows/epoll.rb
+++ b/lib/rainbows/epoll.rb
@@ -36,7 +36,6 @@ module Rainbows::Epoll
   def init_worker_process(worker)
     super
     Rainbows.const_set(:EP, SleepyPenguin::Epoll.new)
-    Rainbows.at_quit { Rainbows::EP.close }
     Rainbows::Client.__send__ :include, Client
     LISTENERS.each { |io| io.extend(Server) }
   end
diff --git a/lib/rainbows/epoll/client.rb b/lib/rainbows/epoll/client.rb
index e23d4e7..d3a06eb 100644
--- a/lib/rainbows/epoll/client.rb
+++ b/lib/rainbows/epoll/client.rb
@@ -10,6 +10,7 @@ module Rainbows::Epoll::Client
   OUT = SleepyPenguin::Epoll::OUT | SleepyPenguin::Epoll::ET
   KATO = {}
   KATO.compare_by_identity if KATO.respond_to?(:compare_by_identity)
+  Rainbows.at_quit { KATO.each_key { |k| k.timeout! }.clear }
   Rainbows.config!(self, :keepalive_timeout)
   EP = Rainbows::EP
   ReRun = []
diff --git a/lib/rainbows/xepoll.rb b/lib/rainbows/xepoll.rb
index b99a66d..91ecfd2 100644
--- a/lib/rainbows/xepoll.rb
+++ b/lib/rainbows/xepoll.rb
@@ -20,7 +20,6 @@ module Rainbows::XEpoll
   def init_worker_process(worker)
     super
     Rainbows.const_set(:EP, SleepyPenguin::Epoll.new)
-    Rainbows.at_quit { Rainbows::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 b33998d..2cf05e5 100644
--- a/lib/rainbows/xepoll_thread_pool/client.rb
+++ b/lib/rainbows/xepoll_thread_pool/client.rb
@@ -37,11 +37,15 @@ 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)
   LOCK = Mutex.new
+  Rainbows.at_quit do
+    clients = nil
+    LOCK.synchronize { clients = KATO.keys; KATO.clear }
+    clients.each { |io| io.closed? or io.close }
+  end
   @@last_expire = Time.now
 
   def kato_set
diff --git a/lib/rainbows/xepoll_thread_spawn/client.rb b/lib/rainbows/xepoll_thread_spawn/client.rb
index 2ab64d2..c6f2301 100644
--- a/lib/rainbows/xepoll_thread_spawn/client.rb
+++ b/lib/rainbows/xepoll_thread_spawn/client.rb
@@ -26,11 +26,15 @@ 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)
   LOCK = Mutex.new
+  Rainbows.at_quit do
+    clients = nil
+    LOCK.synchronize { clients = KATO.keys; KATO.clear }
+    clients.each { |io| io.closed? or io.close }
+  end
   @@last_expire = Time.now
 
   def kato_set