From 278d9d5a7f3d2dc3c6563af1584b5e773e08073d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 26 Nov 2009 00:41:26 -0800 Subject: Fiber*: cleanup scheduling, fix keepalive Both FiberSpawn and FiberPool share similar main loops, the only difference being the handling of connection acceptance. So move the scheduler into it's own function for consistency. We'll also correctly implement keepalive timeout so clients get disconnected at the right time. --- lib/rainbows/fiber_pool.rb | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'lib/rainbows/fiber_pool.rb') diff --git a/lib/rainbows/fiber_pool.rb b/lib/rainbows/fiber_pool.rb index 6cb2ca6..c647676 100644 --- a/lib/rainbows/fiber_pool.rb +++ b/lib/rainbows/fiber_pool.rb @@ -1,6 +1,5 @@ # -*- encoding: binary -*- require 'rainbows/fiber' -require 'pp' module Rainbows @@ -26,26 +25,10 @@ module Rainbows }.resume # resume to hit ::Fiber.yield so it waits on a client } Fiber::Base.const_set(:APP, app) - rd = Fiber::RD - wr = Fiber::WR begin - ret = begin - G.tick - IO.select(rd.keys.concat(LISTENERS), wr.keys, nil, timer) or next - rescue Errno::EINTR - retry - rescue Errno::EBADF, TypeError - LISTENERS.compact! - G.cur > 0 ? retry : break - end - - # active writers first, then _all_ readers for keepalive timeout - ret[1].concat(rd.keys).each { |c| c.f.resume } - - # accept() is an expensive syscall - (ret.first & LISTENERS).each do |l| - fib = pool.shift or break + schedule do |l| + fib = pool.shift or break # let another worker process take it io = begin l.accept_nonblock rescue Errno::EAGAIN, Errno::ECONNABORTED -- cgit v1.2.3-24-ge0c7