1 # -*- encoding: binary -*-
5 Unicorn::SocketHelper::DEFAULTS.merge!({
6 # the value passed to TCP_DEFER_ACCEPT actually matters in Linux 2.6.32+
7 :tcp_defer_accept => 60,
9 # keep-alive performance sucks without this due to
10 # write(headers)-write(body)-read
11 # because we always write headers and bodies with two calls
14 # we always want to send our headers out ASAP since Rainbows!
15 # is designed for apps that could trickle out the body slowly
19 # See http://rainbows.rubyforge.org/ for documentation
24 # map of numeric file descriptors to IO objects to avoid using IO.new
25 # and potentially causing race conditions when using /dev/fd/
27 FD_MAP.compare_by_identity if FD_MAP.respond_to?(:compare_by_identity)
29 require 'rainbows/const'
30 require 'rainbows/http_parser'
31 require 'rainbows/http_server'
32 autoload :Response, 'rainbows/response'
33 autoload :ProcessClient, 'rainbows/process_client'
34 autoload :Client, 'rainbows/client'
35 autoload :Base, 'rainbows/base'
36 autoload :Sendfile, 'rainbows/sendfile'
37 autoload :AppPool, 'rainbows/app_pool'
38 autoload :DevFdResponse, 'rainbows/dev_fd_response'
39 autoload :MaxBody, 'rainbows/max_body'
40 autoload :QueuePool, 'rainbows/queue_pool'
41 autoload :EvCore, 'rainbows/ev_core'
42 autoload :SocketProxy, 'rainbows/socket_proxy'
45 # Sleeps the current application dispatch. This will pick the
46 # optimal method to sleep depending on the concurrency model chosen
47 # (which may still suck and block the entire process). Using this
48 # with the basic :Coolio or :EventMachine models is not recommended.
49 # This should be used within your Rack application.
50 def self.sleep(seconds)
51 case Rainbows.server.use
52 when :FiberPool, :FiberSpawn
53 Rainbows::Fiber.sleep(seconds)
54 when :RevFiberSpawn, :CoolioFiberSpawn
55 Rainbows::Fiber::Coolio::Sleeper.new(seconds)
66 attr_accessor :cur # may not always be used
72 def self.config!(mod, *opts)
73 @forked or abort "#{mod} should only be loaded in a worker process"
75 mod.const_set(opt.to_s.upcase, Rainbows.server.__send__(opt))
84 def self.at_quit(&block)
89 @worker.tick = Time.now.to_i
90 exit!(2) if @expire && Time.now >= @expire
91 @alive && @server.master_pid == Process.ppid or quit!
101 Rainbows::HttpParser.quit
102 @expire = Time.now + (@server.timeout * 2.0)
103 Unicorn::HttpServer::LISTENERS.each { |s| s.close rescue nil }.clear
104 @at_quit.each { |task| task.call }
109 autoload :Base, "rainbows/base"
110 autoload :WriterThreadPool, "rainbows/writer_thread_pool"
111 autoload :WriterThreadSpawn, "rainbows/writer_thread_spawn"
112 autoload :Revactor, "rainbows/revactor"
113 autoload :ThreadSpawn, "rainbows/thread_spawn"
114 autoload :ThreadPool, "rainbows/thread_pool"
115 autoload :Rev, "rainbows/rev"
116 autoload :RevThreadSpawn, "rainbows/rev_thread_spawn"
117 autoload :RevThreadPool, "rainbows/rev_thread_pool"
118 autoload :RevFiberSpawn, "rainbows/rev_fiber_spawn"
119 autoload :Coolio, "rainbows/coolio"
120 autoload :CoolioThreadSpawn, "rainbows/coolio_thread_spawn"
121 autoload :CoolioThreadPool, "rainbows/coolio_thread_pool"
122 autoload :CoolioFiberSpawn, "rainbows/coolio_fiber_spawn"
123 autoload :Epoll, "rainbows/epoll"
124 autoload :XEpoll, "rainbows/xepoll"
125 autoload :EventMachine, "rainbows/event_machine"
126 autoload :FiberSpawn, "rainbows/fiber_spawn"
127 autoload :FiberPool, "rainbows/fiber_pool"
128 autoload :ActorSpawn, "rainbows/actor_spawn"
129 autoload :NeverBlock, "rainbows/never_block"
130 autoload :XEpollThreadSpawn, "rainbows/xepoll_thread_spawn"
131 autoload :XEpollThreadPool, "rainbows/xepoll_thread_pool"
132 autoload :StreamResponseEpoll, "rainbows/stream_response_epoll"
134 autoload :Fiber, 'rainbows/fiber' # core class
135 autoload :StreamFile, 'rainbows/stream_file'
136 autoload :HttpResponse, 'rainbows/http_response' # deprecated
137 autoload :ThreadTimeout, 'rainbows/thread_timeout'
138 autoload :WorkerYield, 'rainbows/worker_yield'
139 autoload :SyncClose, 'rainbows/sync_close'
140 autoload :ReverseProxy, 'rainbows/reverse_proxy'
141 autoload :JoinThreads, 'rainbows/join_threads'
142 autoload :PoolSize, 'rainbows/pool_size'
145 require 'rainbows/error'
146 require 'rainbows/configurator'