Module: Rainbows
- Defined in:
- lib/rainbows.rb,
lib/rainbows/server_token.rb
Overview
See yhbt.net/rainbows/ for documentation
Defined Under Namespace
Modules: ActorSpawn, Base, Configurator, Coolio, CoolioThreadPool, CoolioThreadSpawn, Epoll, EventMachine, FiberPool, FiberSpawn, NeverBlock, Rev, RevFiberSpawn, RevThreadPool, RevThreadSpawn, Revactor, StreamResponseEpoll, ThreadPool, ThreadSpawn, WorkerYield, WriterThreadPool, WriterThreadSpawn, XEpoll, XEpollThreadPool, XEpollThreadSpawn Classes: AppPool, DevFdResponse, MaxBody, Sendfile, ServerToken, ThreadTimeout
Constant Summary collapse
- O =
:stopdoc:
{}
- FD_MAP =
map of numeric file descriptors to IO objects to avoid using IO.new and potentially causing race conditions when using /dev/fd/
{}.compare_by_identity
Class Attribute Summary collapse
-
.alive ⇒ Object
readonly
Returns the value of attribute alive.
-
.cur ⇒ Object
may not always be used.
-
.forked ⇒ Object
writeonly
Sets the attribute forked.
-
.readers ⇒ Object
writeonly
Sets the attribute readers.
-
.server ⇒ Object
Returns the value of attribute server.
-
.worker ⇒ Object
writeonly
Sets the attribute worker.
Class Method Summary collapse
- .at_quit(&block) ⇒ Object
- .config!(mod, *opts) ⇒ Object
- .cur_alive ⇒ Object
- .quit! ⇒ Object
-
.sleep(seconds) ⇒ Object
:startdoc: Sleeps the current application dispatch.
- .tick ⇒ Object
Class Attribute Details
.alive ⇒ Object (readonly)
Returns the value of attribute alive.
54 55 56 |
# File 'lib/rainbows.rb', line 54 def alive @alive end |
.cur ⇒ Object
may not always be used
53 54 55 |
# File 'lib/rainbows.rb', line 53 def cur @cur end |
.forked=(value) ⇒ Object (writeonly)
Sets the attribute forked
56 57 58 |
# File 'lib/rainbows.rb', line 56 def forked=(value) @forked = value end |
.readers=(value) ⇒ Object (writeonly)
Sets the attribute readers
57 58 59 |
# File 'lib/rainbows.rb', line 57 def readers=(value) @readers = value end |
.server ⇒ Object
Returns the value of attribute server.
52 53 54 |
# File 'lib/rainbows.rb', line 52 def server @server end |
.worker=(value) ⇒ Object (writeonly)
Sets the attribute worker
55 56 57 |
# File 'lib/rainbows.rb', line 55 def worker=(value) @worker = value end |
Class Method Details
.at_quit(&block) ⇒ Object
72 73 74 |
# File 'lib/rainbows.rb', line 72 def self.at_quit(&block) @at_quit << block end |
.config!(mod, *opts) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/rainbows.rb', line 60 def self.config!(mod, *opts) @forked or abort "#{mod} should only be loaded in a worker process" opts.each do |opt| mod.const_set(opt.to_s.upcase, Rainbows.server.__send__(opt)) end end |
.cur_alive ⇒ Object
82 83 84 |
# File 'lib/rainbows.rb', line 82 def self.cur_alive @alive || @cur > 0 end |
.quit! ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/rainbows.rb', line 86 def self.quit! unless @expire @alive = false Rainbows::HttpParser.quit @expire = now + (@server.timeout * 2.0) tmp = @readers.dup @readers.clear tmp.each { |s| s.close rescue nil }.clear @at_quit.each(&:call) # XXX hack to break out of IO.select in worker_loop for some models Process.kill(:QUIT, $$) end false end |
.sleep(seconds) ⇒ Object
:startdoc: Sleeps the current application dispatch. This will pick the optimal method to sleep depending on the concurrency model chosen (which may still suck and block the entire process). Using this with the basic :Coolio or :EventMachine models is not recommended. This should be used within your Rack application.
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rainbows.rb', line 37 def self.sleep(seconds) case Rainbows.server.use when :FiberPool, :FiberSpawn Rainbows::Fiber.sleep(seconds) when :RevFiberSpawn, :CoolioFiberSpawn Rainbows::Fiber::Coolio::Sleeper.new(seconds) when :Revactor Actor.sleep(seconds) else Kernel.sleep(seconds) end end |
.tick ⇒ Object
76 77 78 79 80 |
# File 'lib/rainbows.rb', line 76 def self.tick @worker.tick = now.to_i exit!(2) if @expire && now >= @expire @alive && @server.master_pid == Process.ppid or quit! end |