globally refactor Range handling for responses
[rainbows.git] / lib / rainbows / base.rb
blob5d5606390ef367fd7abfac1035990f6eb5323fab
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   # shortcuts...
12   G = Rainbows::G
14   # this method is called by all current concurrency models
15   def init_worker_process(worker) # :nodoc:
16     super(worker)
17     Rainbows::Response.setup(self.class)
18     Rainbows::MaxBody.setup
19     Rainbows::RackInput.setup
20     G.tmp = worker.tmp
22     listeners = Rainbows::HttpServer::LISTENERS
23     Rainbows::HttpServer::IO_PURGATORY.concat(listeners)
25     # we're don't use the self-pipe mechanism in the Rainbows! worker
26     # since we don't defer reopening logs
27     Rainbows::HttpServer::SELF_PIPE.each { |x| x.close }.clear
28     trap(:USR1) { reopen_worker_logs(worker.nr) }
29     trap(:QUIT) { G.quit! }
30     [:TERM, :INT].each { |sig| trap(sig) { exit!(0) } } # instant shutdown
31     Rainbows::ProcessClient.const_set(:APP, G.server.app)
32     logger.info "Rainbows! #@use worker_connections=#@worker_connections"
33   end
35   def process_client(client)
36     client.process_loop
37   end
39   def self.included(klass) # :nodoc:
40     klass.const_set :LISTENERS, Rainbows::HttpServer::LISTENERS
41     klass.const_set :G, Rainbows::G
42   end
44   # :startdoc:
45 end