eliminate G constant and just use the Rainbows! module
[rainbows.git] / lib / rainbows / base.rb
blobb94ddc990075c64c1179c7840b9e94c875385217
1 # -*- encoding: binary -*-
3 # base class for \Rainbows! concurrency models, this is currently used by
4 # ThreadSpawn and ThreadPool models.  Base is also its own
5 # (non-)concurrency model which is basically Unicorn-with-keepalive, and
6 # not intended for production use, as keepalive with a pure prefork
7 # concurrency model is extremely expensive.
8 module Rainbows::Base
9   # :stopdoc:
11   # this method is called by all current concurrency models
12   def init_worker_process(worker) # :nodoc:
13     super(worker)
14     Rainbows::Response.setup(self.class)
15     Rainbows::MaxBody.setup
16     Rainbows::RackInput.setup
17     Rainbows.tick_io = worker.tmp
19     listeners = Rainbows::HttpServer::LISTENERS
20     Rainbows::HttpServer::IO_PURGATORY.concat(listeners)
22     # we're don't use the self-pipe mechanism in the Rainbows! worker
23     # since we don't defer reopening logs
24     Rainbows::HttpServer::SELF_PIPE.each { |x| x.close }.clear
25     trap(:USR1) { reopen_worker_logs(worker.nr) }
26     trap(:QUIT) { Rainbows.quit! }
27     [:TERM, :INT].each { |sig| trap(sig) { exit!(0) } } # instant shutdown
28     Rainbows::ProcessClient.const_set(:APP, Rainbows.server.app)
29     logger.info "Rainbows! #@use worker_connections=#@worker_connections"
30   end
32   def process_client(client)
33     client.process_loop
34   end
36   def self.included(klass) # :nodoc:
37     klass.const_set :LISTENERS, Rainbows::HttpServer::LISTENERS
38   end
40   # :startdoc:
41 end