respect client_body_buffer_size in Unicorn 3.1.0
[rainbows.git] / lib / rainbows / rev / core.rb
blob5c5b7993612ec613bbaa59d63513c78f3ce261d0
1 # -*- encoding: binary -*-
2 # :enddoc:
3 require 'rev'
4 Rev::VERSION >= '0.3.0' or abort 'rev >= 0.3.0 is required'
5 require 'rainbows/rev/heartbeat'
7 module Rainbows
8   module Rev
9     class Server < ::Rev::IO
10       # CL and MAX will be defined in the corresponding worker loop
12       def on_readable
13         return if CONN.size >= MAX
14         io = @_io.kgio_tryaccept and CL.new(io).attach(LOOP)
15       end
16     end # class Server
18     module Core
19       include Base
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) }
37         rloop.run
38       end
40     end # module Core
41   end # module Rev
42 end # module Rainbows