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