about summary refs log tree commit homepage
path: root/lib/rainbows/fiber_spawn.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-11-26 00:41:26 -0800
committerEric Wong <normalperson@yhbt.net>2009-11-26 13:41:06 -0800
commit278d9d5a7f3d2dc3c6563af1584b5e773e08073d (patch)
treea3066da21425c49f3ca89bb8cf3af2ab03c285d0 /lib/rainbows/fiber_spawn.rb
parent1079dfa30108466d413f30526eda468cdf0ae985 (diff)
downloadrainbows-278d9d5a7f3d2dc3c6563af1584b5e773e08073d.tar.gz
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.
Diffstat (limited to 'lib/rainbows/fiber_spawn.rb')
-rw-r--r--lib/rainbows/fiber_spawn.rb23
1 files changed, 2 insertions, 21 deletions
diff --git a/lib/rainbows/fiber_spawn.rb b/lib/rainbows/fiber_spawn.rb
index 004976a..83b64de 100644
--- a/lib/rainbows/fiber_spawn.rb
+++ b/lib/rainbows/fiber_spawn.rb
@@ -17,28 +17,10 @@ module Rainbows
       init_worker_process(worker)
       Fiber::Base.const_set(:APP, app)
       limit = worker_connections
-      rd = Rainbows::Fiber::RD
-      wr = Rainbows::Fiber::WR
       fio = Rainbows::Fiber::IO
 
       begin
-        ret = begin
-          IO.select(rd.keys.concat(LISTENERS), wr.keys, nil, timer) or next
-        rescue Errno::EINTR
-          G.tick
-          retry
-        rescue Errno::EBADF, TypeError
-          LISTENERS.compact!
-          G.cur > 0 ? retry : break
-        end
-        G.tick
-
-        # active writers first, then _all_ readers for keepalive timeout
-        ret[1].concat(rd.keys).each { |c| c.f.resume }
-        G.tick
-
-        # accept() is an expensive syscall
-        (ret.first & LISTENERS).each do |l|
+        schedule do |l|
           break if G.cur >= limit
           io = begin
             l.accept_nonblock
@@ -47,10 +29,9 @@ module Rainbows
           end
           ::Fiber.new { process_client(fio.new(io, ::Fiber.current)) }.resume
         end
-        G.tick
       rescue => e
         listen_loop_error(e)
-      end while G.tick || G.cur > 0
+      end while G.alive || G.cur > 0
     end
 
   end