1 # -*- encoding: binary -*-
4 # the value passed to TCP_DEFER_ACCEPT actually matters in Linux 2.6.32+
5 Unicorn::SocketHelper::DEFAULTS[:tcp_defer_accept] = 60
7 # See http://rainbows.bogomips.org/ for documentation
12 # map of numeric file descriptors to IO objects to avoid using IO.new
13 # and potentially causing race conditions when using /dev/fd/
15 FD_MAP.compare_by_identity if FD_MAP.respond_to?(:compare_by_identity)
17 require 'rainbows/const'
18 require 'rainbows/http_parser'
19 require 'rainbows/http_server'
20 autoload :Response, 'rainbows/response'
21 autoload :ProcessClient, 'rainbows/process_client'
22 autoload :Client, 'rainbows/client'
23 autoload :Base, 'rainbows/base'
24 autoload :Sendfile, 'rainbows/sendfile'
25 autoload :AppPool, 'rainbows/app_pool'
26 autoload :DevFdResponse, 'rainbows/dev_fd_response'
27 autoload :MaxBody, 'rainbows/max_body'
28 autoload :QueuePool, 'rainbows/queue_pool'
29 autoload :EvCore, 'rainbows/ev_core'
30 autoload :SocketProxy, 'rainbows/socket_proxy'
33 # Sleeps the current application dispatch. This will pick the
34 # optimal method to sleep depending on the concurrency model chosen
35 # (which may still suck and block the entire process). Using this
36 # with the basic :Coolio or :EventMachine models is not recommended.
37 # This should be used within your Rack application.
38 def self.sleep(seconds)
39 case Rainbows.server.use
40 when :FiberPool, :FiberSpawn
41 Rainbows::Fiber.sleep(seconds)
42 when :RevFiberSpawn, :CoolioFiberSpawn
43 Rainbows::Fiber::Coolio::Sleeper.new(seconds)
54 attr_accessor :cur # may not always be used
61 def self.config!(mod, *opts)
62 @forked or abort "#{mod} should only be loaded in a worker process"
64 mod.const_set(opt.to_s.upcase, Rainbows.server.__send__(opt))
73 def self.at_quit(&block)
78 @worker.tick = Time.now.to_i
79 exit!(2) if @expire && Time.now >= @expire
80 @alive && @server.master_pid == Process.ppid or quit!
90 Rainbows::HttpParser.quit
91 @expire = Time.now + (@server.timeout * 2.0)
94 tmp.each { |s| s.close rescue nil }.clear
95 @at_quit.each { |task| task.call }
100 autoload :Base, "rainbows/base"
101 autoload :WriterThreadPool, "rainbows/writer_thread_pool"
102 autoload :WriterThreadSpawn, "rainbows/writer_thread_spawn"
103 autoload :Revactor, "rainbows/revactor"
104 autoload :ThreadSpawn, "rainbows/thread_spawn"
105 autoload :ThreadPool, "rainbows/thread_pool"
106 autoload :Rev, "rainbows/rev"
107 autoload :RevThreadSpawn, "rainbows/rev_thread_spawn"
108 autoload :RevThreadPool, "rainbows/rev_thread_pool"
109 autoload :RevFiberSpawn, "rainbows/rev_fiber_spawn"
110 autoload :Coolio, "rainbows/coolio"
111 autoload :CoolioThreadSpawn, "rainbows/coolio_thread_spawn"
112 autoload :CoolioThreadPool, "rainbows/coolio_thread_pool"
113 autoload :CoolioFiberSpawn, "rainbows/coolio_fiber_spawn"
114 autoload :Epoll, "rainbows/epoll"
115 autoload :XEpoll, "rainbows/xepoll"
116 autoload :EventMachine, "rainbows/event_machine"
117 autoload :FiberSpawn, "rainbows/fiber_spawn"
118 autoload :FiberPool, "rainbows/fiber_pool"
119 autoload :ActorSpawn, "rainbows/actor_spawn"
120 autoload :NeverBlock, "rainbows/never_block"
121 autoload :XEpollThreadSpawn, "rainbows/xepoll_thread_spawn"
122 autoload :XEpollThreadPool, "rainbows/xepoll_thread_pool"
123 autoload :StreamResponseEpoll, "rainbows/stream_response_epoll"
125 autoload :Fiber, 'rainbows/fiber' # core class
126 autoload :StreamFile, 'rainbows/stream_file'
127 autoload :ThreadTimeout, 'rainbows/thread_timeout'
128 autoload :WorkerYield, 'rainbows/worker_yield'
129 autoload :SyncClose, 'rainbows/sync_close'
130 autoload :ReverseProxy, 'rainbows/reverse_proxy'
131 autoload :JoinThreads, 'rainbows/join_threads'
132 autoload :PoolSize, 'rainbows/pool_size'
135 require 'rainbows/error'
136 require 'rainbows/configurator'