1 # -*- encoding: binary -*-
4 Rev::VERSION >= '0.3.0' or abort 'rev >= 0.3.0 is required'
5 require 'rainbows/rev/heartbeat'
9 class Server < ::Rev::IO
10 # CL and MAX will be defined in the corresponding worker loop
13 return if CONN.size >= MAX
14 io = @_io.kgio_tryaccept and CL.new(io).attach(LOOP)
21 # runs inside each forked worker, this sits around and waits
22 # for connections and doesn't die until the parent dies (or is
23 # given a INT, QUIT, or TERM signal)
24 def worker_loop(worker)
25 Rainbows::Response.setup(Rainbows::Rev::Client)
26 require 'rainbows/rev/sendfile'
27 Rainbows::Rev::Client.__send__(:include, Rainbows::Rev::Sendfile)
28 init_worker_process(worker)
29 mod = Rainbows.const_get(@use)
30 rloop = Server.const_set(:LOOP, ::Rev::Loop.default)
31 Server.const_set(:MAX, @worker_connections)
32 Server.const_set(:CL, mod.const_get(:Client))
33 EvCore.const_set(:APP, G.server.app)
34 Rainbows::EvCore.setup
35 Heartbeat.new(1, true).attach(rloop)
36 LISTENERS.map! { |s| Server.new(s).attach(rloop) }