1 # -*- encoding: binary -*-
3 Rev::VERSION >= '0.3.0' or abort 'rev >= 0.3.0 is required'
4 IO::Buffer.respond_to?(:default_node_size=) and
5 IO::Buffer.default_node_size = Rev::IO::INPUT_SIZE
6 require 'rainbows/rev/heartbeat'
10 class Server < ::Rev::IO
12 LOOP = ::Rev::Loop.default
13 # CL and MAX will be defined in the corresponding worker loop
16 return if CONN.size >= MAX
18 CL.new(@_io.accept_nonblock).attach(LOOP)
19 rescue Errno::EAGAIN, Errno::ECONNABORTED
27 # runs inside each forked worker, this sits around and waits
28 # for connections and doesn't die until the parent dies (or is
29 # given a INT, QUIT, or TERM signal)
30 def worker_loop(worker)
31 init_worker_process(worker)
32 mod = self.class.const_get(@use)
33 Server.const_set(:MAX, @worker_connections)
34 Server.const_set(:CL, mod.const_get(:Client))
36 rloop = ::Rev::Loop.default
37 Heartbeat.new(1, true).attach(rloop)
38 LISTENERS.map! { |s| Server.new(s).attach(rloop) }