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
24 ret = select(RD.compact.concat(LISTENERS), WR.compact, nil, t)
27 rescue Errno::EBADF, TypeError
32 # active writers first, then readers
33 ret[1].concat(RD.compact & ret[0]).each { |c| c.f.resume }
35 # accept is an expensive syscall, filter out listeners we don't want
36 (ret[0] & LISTENERS).each { |x| yield x }
39 # wakes up any sleepers or keepalive-timeout violators that need to be
40 # woken and returns an interval to IO.select on
45 ZZ.delete_if { |fib, time|
53 fibs.each { |fib| fib.resume }
55 max_sleep = 1.0 # wake up semi-frequently to prevent SIGKILL from master
59 return max_sleep if max > max_sleep
74 def self.setup(klass, app)
75 Rainbows::Client.__send__(:include, Rainbows::Fiber::IO::Methods)
76 require 'rainbows/fiber/body'
77 Rainbows::Client.__send__(:include, Rainbows::Fiber::Body)
78 self.const_set(:APP, app)