1 # -*- encoding: binary -*-
3 require 'rainbows/fiber/io'
5 module Rainbows::Fiber::Base
10 RD = Rainbows::Fiber::RD
11 WR = Rainbows::Fiber::WR
12 ZZ = Rainbows::Fiber::ZZ
15 # the scheduler method that powers both FiberSpawn and FiberPool
16 # concurrency models. It times out idle clients and attempts to
17 # schedules ones that were blocked on I/O. At most it'll sleep
18 # for one second (returned by the schedule_sleepers method) which
23 RD.compact.each { |c| c.f.resume } # attempt to time out idle clients
25 Kernel.select(RD.compact.concat(LISTENERS), WR.compact, nil, t) or return
28 rescue Errno::EBADF, TypeError
33 # active writers first, then _all_ readers for keepalive timeout
34 ret[1].concat(RD.compact).each { |c| c.f.resume }
36 # accept is an expensive syscall, filter out listeners we don't want
37 (ret[0] & LISTENERS).each(&block)
40 # wakes up any sleepers that need to be woken and
41 # returns an interval to IO.select on
46 ZZ.delete_if { |fib, time|
54 fibs.each { |fib| fib.resume }
56 max.nil? || max > (now + 1) ? 1 : max - now
61 process_client(client)
67 def self.setup(klass, app)
68 require 'rainbows/fiber/body'
69 klass.__send__(:include, Rainbows::Fiber::Body)
70 self.const_set(:APP, app)