about summary refs log tree commit homepage
path: root/lib/rainbows/fiber/base.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-27 03:56:30 +0000
committerEric Wong <normalperson@yhbt.net>2010-12-27 04:05:18 +0000
commit40c22b3f0a2ace6e4b51a39624ac5ed5ee3d0162 (patch)
treeb4a5d4b5aa8bbec9851bbe77a5e524d614e30856 /lib/rainbows/fiber/base.rb
parentabb3f7e057bd5fb0aa97cae1410ce2f55ba12b9c (diff)
downloadrainbows-40c22b3f0a2ace6e4b51a39624ac5ed5ee3d0162.tar.gz
We can use the same interface as Rainbows::Fiber.sleep to avoid
blindly waking up readers at ever scheduler invocation.
Diffstat (limited to 'lib/rainbows/fiber/base.rb')
-rw-r--r--lib/rainbows/fiber/base.rb13
1 files changed, 6 insertions, 7 deletions
diff --git a/lib/rainbows/fiber/base.rb b/lib/rainbows/fiber/base.rb
index ccfda96..b693451 100644
--- a/lib/rainbows/fiber/base.rb
+++ b/lib/rainbows/fiber/base.rb
@@ -18,11 +18,10 @@ module Rainbows::Fiber::Base
   # for one second (returned by the schedule_sleepers method) which
   # will cause it.
   def schedule(&block)
-    ret = begin
+    begin
       G.tick
-      RD.compact.each { |c| c.f.resume } # attempt to time out idle clients
       t = schedule_sleepers
-      select(RD.compact.concat(LISTENERS), WR.compact, nil, t) or return
+      ret = select(RD.compact.concat(LISTENERS), WR.compact, nil, t)
     rescue Errno::EINTR
       retry
     rescue Errno::EBADF, TypeError
@@ -30,15 +29,15 @@ module Rainbows::Fiber::Base
       raise
     end or return
 
-    # active writers first, then _all_ readers for keepalive timeout
-    ret[1].concat(RD.compact).each { |c| c.f.resume }
+    # active writers first, then readers
+    ret[1].concat(RD.compact & ret[0]).each { |c| c.f.resume }
 
     # accept is an expensive syscall, filter out listeners we don't want
     (ret[0] & LISTENERS).each(&block)
   end
 
-  # wakes up any sleepers that need to be woken and
-  # returns an interval to IO.select on
+  # wakes up any sleepers or keepalive-timeout violators that need to be
+  # woken and returns an interval to IO.select on
   def schedule_sleepers
     max = nil
     now = Time.now