diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-07-10 08:04:48 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-07-10 08:04:48 +0000 |
commit | d3b97d1114e2d23a9231fe889cd5bf6927d451ba (patch) | |
tree | 6c4d7a033dad1edc91b72a9e7fa36203c60c8116 | |
parent | 9838b614621bbbff27a91166406d833be85adbbd (diff) | |
download | rainbows-d3b97d1114e2d23a9231fe889cd5bf6927d451ba.tar.gz |
Since we suck at building websites, we just rely on RDoc as a website builder. And since Rainbows! is an application server (and not a programming library), our internal API should be of little interest to end users. Anybody interested in Rainbows! (or any other project) internals should be reading the source.
43 files changed, 83 insertions, 58 deletions
diff --git a/lib/rainbows.rb b/lib/rainbows.rb index 4e9578b..d0b3e8a 100644 --- a/lib/rainbows.rb +++ b/lib/rainbows.rb @@ -12,6 +12,7 @@ module Rainbows # global vars because class/instance variables are confusing me :< # this struct is only accessed inside workers and thus private to each # G.cur may not be used in the network concurrency model + # :stopdoc: class State < Struct.new(:alive,:m,:cur,:kato,:server,:tmp,:expire) def tick tmp.chmod(self.m = m == 0 ? 1 : 0) @@ -26,7 +27,6 @@ module Rainbows false end end - # :stopdoc: G = State.new(true, 0, 0, 5) O = {} # :startdoc: @@ -64,12 +64,12 @@ module Rainbows # runs the Rainbows! HttpServer with +app+ and +options+ and does # not return until the server has exited. - def run(app, options = {}) + def run(app, options = {}) # :nodoc: HttpServer.new(app, options).start.join end # returns nil if accept fails - def sync_accept(sock) + def sync_accept(sock) # :nodoc: rv = sock.accept rv.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) rv @@ -77,7 +77,7 @@ module Rainbows end # returns nil if accept fails - def accept(sock) + def accept(sock) # :nodoc: rv = sock.accept_nonblock rv.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) rv @@ -87,16 +87,18 @@ module Rainbows # returns a string representing the address of the given client +io+ # For local UNIX domain sockets, this will return a string referred # to by the (non-frozen) Unicorn::HttpRequest::LOCALHOST constant. - def addr(io) + def addr(io) # :nodoc: io.respond_to?(:peeraddr) ? io.peeraddr[-1] : Unicorn::HttpRequest::LOCALHOST end + # :stopdoc: # the default max body size is 1 megabyte (1024 * 1024 bytes) @@max_bytes = 1024 * 1024 def max_bytes; @@max_bytes; end def max_bytes=(nr); @@max_bytes = nr; end + # :startdoc: end # :stopdoc: diff --git a/lib/rainbows/actor_spawn.rb b/lib/rainbows/actor_spawn.rb index 98e85bc..8cb839d 100644 --- a/lib/rainbows/actor_spawn.rb +++ b/lib/rainbows/actor_spawn.rb @@ -20,7 +20,7 @@ module Rainbows # runs inside each forked worker, this sits around and waits # for connections and doesn't die until the parent dies (or is # given a INT, QUIT, or TERM signal) - def worker_loop(worker) + def worker_loop(worker) # :nodoc: Const::RACK_DEFAULTS["rack.multithread"] = true # :( init_worker_process(worker) accept_loop(Actor) diff --git a/lib/rainbows/app_pool.rb b/lib/rainbows/app_pool.rb index a1a3119..7996e2b 100644 --- a/lib/rainbows/app_pool.rb +++ b/lib/rainbows/app_pool.rb @@ -82,7 +82,7 @@ module Rainbows end # Rack application endpoint, +env+ is the Rack environment - def call(env) + def call(env) # :nodoc: # we have to do this check at call time (and not initialize) # because of preload_app=true and models being changeable with SIGHUP diff --git a/lib/rainbows/base.rb b/lib/rainbows/base.rb index a619b00..3fb5a94 100644 --- a/lib/rainbows/base.rb +++ b/lib/rainbows/base.rb @@ -19,7 +19,7 @@ module Rainbows::Base HttpParser = Unicorn::HttpParser # this method is called by all current concurrency models - def init_worker_process(worker) + def init_worker_process(worker) # :nodoc: super(worker) Rainbows::Response.setup(self.class) Rainbows::MaxBody.setup @@ -40,7 +40,7 @@ module Rainbows::Base logger.info "Rainbows! #@use worker_connections=#@worker_connections" end - def wait_headers_readable(client) + def wait_headers_readable(client) # :nodoc: IO.select([client], nil, nil, G.kato) end @@ -48,7 +48,7 @@ module Rainbows::Base # in 3 easy steps: read request, call app, write app response # this is used by synchronous concurrency models # Base, ThreadSpawn, ThreadPool - def process_client(client) + def process_client(client) # :nodoc: buf = client.readpartial(CHUNK_SIZE) # accept filters protect us here hp = HttpParser.new env = {} @@ -87,7 +87,7 @@ module Rainbows::Base client.close unless client.closed? end - def self.included(klass) + def self.included(klass) # :nodoc: klass.const_set :LISTENERS, Rainbows::HttpServer::LISTENERS klass.const_set :G, Rainbows::G end diff --git a/lib/rainbows/byte_slice.rb b/lib/rainbows/byte_slice.rb index 2d5586c..3bb4dd7 100644 --- a/lib/rainbows/byte_slice.rb +++ b/lib/rainbows/byte_slice.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: module Rainbows::ByteSlice if String.method_defined?(:encoding) def byte_slice(buf, range) diff --git a/lib/rainbows/const.rb b/lib/rainbows/const.rb index feed443..f9ae861 100644 --- a/lib/rainbows/const.rb +++ b/lib/rainbows/const.rb @@ -1,5 +1,5 @@ # -*- encoding: binary -*- - +# :enddoc: module Rainbows module Const diff --git a/lib/rainbows/error.rb b/lib/rainbows/error.rb index d90dad0..8b4d9ff 100644 --- a/lib/rainbows/error.rb +++ b/lib/rainbows/error.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: module Rainbows class Error diff --git a/lib/rainbows/ev_core.rb b/lib/rainbows/ev_core.rb index 74e67f3..5ca693b 100644 --- a/lib/rainbows/ev_core.rb +++ b/lib/rainbows/ev_core.rb @@ -1,5 +1,5 @@ # -*- encoding: binary -*- - +# :enddoc: module Rainbows # base module for evented models like Rev and EventMachine diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb index bbb38fa..173340e 100644 --- a/lib/rainbows/event_machine.rb +++ b/lib/rainbows/event_machine.rb @@ -48,7 +48,7 @@ module Rainbows include Base - class Client < EM::Connection + class Client < EM::Connection # :nodoc: all include Rainbows::EvCore include Rainbows::Response G = Rainbows::G @@ -149,7 +149,7 @@ module Rainbows end end - module ResponsePipe + module ResponsePipe # :nodoc: all def initialize(client) @client = client end @@ -160,7 +160,7 @@ module Rainbows end end - module ResponseChunkPipe + module ResponseChunkPipe # :nodoc: all include ResponsePipe def unbind @@ -187,7 +187,7 @@ module Rainbows end end - module Server + module Server # :nodoc: all def close detach @@ -205,7 +205,7 @@ module Rainbows # Middleware that will run the app dispatch in a separate thread. # This middleware is automatically loaded by Rainbows! when using # EventMachine and if the app responds to the +deferred?+ method. - class TryDefer < Struct.new(:app) + class TryDefer < Struct.new(:app) # :nodoc: all def initialize(app) # the entire app becomes multithreaded, even the root (non-deferred) @@ -226,7 +226,7 @@ module Rainbows end end - def init_worker_process(worker) + def init_worker_process(worker) # :nodoc: Rainbows::Response.setup(Rainbows::EventMachine::Client) super end @@ -234,7 +234,7 @@ module Rainbows # runs inside each forked worker, this sits around and waits # for connections and doesn't die until the parent dies (or is # given a INT, QUIT, or TERM signal) - def worker_loop(worker) + def worker_loop(worker) # :nodoc: init_worker_process(worker) G.server.app.respond_to?(:deferred?) and G.server.app = TryDefer[G.server.app] diff --git a/lib/rainbows/fiber.rb b/lib/rainbows/fiber.rb index ec0cee3..e65ef1b 100644 --- a/lib/rainbows/fiber.rb +++ b/lib/rainbows/fiber.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: begin require 'fiber' rescue LoadError diff --git a/lib/rainbows/fiber/base.rb b/lib/rainbows/fiber/base.rb index 9ac3b72..b3a4c89 100644 --- a/lib/rainbows/fiber/base.rb +++ b/lib/rainbows/fiber/base.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: require 'rainbows/fiber/io' module Rainbows diff --git a/lib/rainbows/fiber/body.rb b/lib/rainbows/fiber/body.rb index 3de45ee..ab5cfc8 100644 --- a/lib/rainbows/fiber/body.rb +++ b/lib/rainbows/fiber/body.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: # non-portable body handling for Fiber-based concurrency goes here # this module is required and included in worker processes only # this is meant to be included _after_ Rainbows::Response::Body diff --git a/lib/rainbows/fiber/io.rb b/lib/rainbows/fiber/io.rb index f6b8bdf..596aeae 100644 --- a/lib/rainbows/fiber/io.rb +++ b/lib/rainbows/fiber/io.rb @@ -21,7 +21,6 @@ module Rainbows def peeraddr to_io.respond_to?(:peeraddr) ? to_io.peeraddr : [ LOCALHOST ] end - # :stopdoc: # for wrapping output response bodies def each(&block) diff --git a/lib/rainbows/fiber/queue.rb b/lib/rainbows/fiber/queue.rb index 384fe2b..e7118f3 100644 --- a/lib/rainbows/fiber/queue.rb +++ b/lib/rainbows/fiber/queue.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: module Rainbows module Fiber diff --git a/lib/rainbows/fiber/rev.rb b/lib/rainbows/fiber/rev.rb index a1ffe33..1babad3 100644 --- a/lib/rainbows/fiber/rev.rb +++ b/lib/rainbows/fiber/rev.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: require 'rev' require 'rainbows/fiber' require 'rainbows/fiber/io' diff --git a/lib/rainbows/fiber_pool.rb b/lib/rainbows/fiber_pool.rb index 745e2a5..42f6dbe 100644 --- a/lib/rainbows/fiber_pool.rb +++ b/lib/rainbows/fiber_pool.rb @@ -16,7 +16,7 @@ module Rainbows module FiberPool include Fiber::Base - def worker_loop(worker) + def worker_loop(worker) # :nodoc: init_worker_process(worker) pool = [] worker_connections.times { diff --git a/lib/rainbows/fiber_spawn.rb b/lib/rainbows/fiber_spawn.rb index 40971e7..df72e70 100644 --- a/lib/rainbows/fiber_spawn.rb +++ b/lib/rainbows/fiber_spawn.rb @@ -13,7 +13,7 @@ module Rainbows module FiberSpawn include Fiber::Base - def worker_loop(worker) + def worker_loop(worker) # :nodoc: init_worker_process(worker) Fiber::Base.setup(self.class, app) limit = worker_connections diff --git a/lib/rainbows/http_response.rb b/lib/rainbows/http_response.rb index 40a7330..ddab2f8 100644 --- a/lib/rainbows/http_response.rb +++ b/lib/rainbows/http_response.rb @@ -1,7 +1,7 @@ # -*- encoding: binary -*- +# :enddoc: # deprecated, use Rainbows::Response instead # Cramp 0.11 relies on this, and is only activated by Cramp -# :enddoc: if defined?(Cramp) && defined?(Rainbows::EventMachine::Client) class Rainbows::HttpResponse class << self diff --git a/lib/rainbows/http_server.rb b/lib/rainbows/http_server.rb index 43604af..72e2c7f 100644 --- a/lib/rainbows/http_server.rb +++ b/lib/rainbows/http_server.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: module Rainbows class HttpServer < ::Unicorn::HttpServer diff --git a/lib/rainbows/max_body.rb b/lib/rainbows/max_body.rb index ca63ea4..23e4fa6 100644 --- a/lib/rainbows/max_body.rb +++ b/lib/rainbows/max_body.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: module Rainbows # middleware used to enforce client_max_body_size for TeeInput users, diff --git a/lib/rainbows/never_block.rb b/lib/rainbows/never_block.rb index 06bb496..9f050a5 100644 --- a/lib/rainbows/never_block.rb +++ b/lib/rainbows/never_block.rb @@ -18,13 +18,14 @@ module Rainbows # module NeverBlock + # :stopdoc: DEFAULTS = { :pool_size => 20, # same default size used by NB :backend => :EventMachine, # NeverBlock doesn't support Rev yet } # same pool size NB core itself uses - def self.setup + def self.setup # :nodoc: DEFAULTS.each { |k,v| O[k] ||= v } Integer === O[:pool_size] && O[:pool_size] > 0 or raise ArgumentError, "pool_size must a be an Integer > 0" @@ -34,7 +35,7 @@ module Rainbows G.server.extend(Core) end - module Core + module Core # :nodoc: all def self.setup self.const_set(:POOL, ::NB::Pool::FiberPool.new(O[:pool_size])) base = O[:backend].to_s.gsub!(/([a-z])([A-Z])/, '\1_\2').downcase! @@ -57,9 +58,7 @@ module Rainbows end end end - end - module Core def init_worker_process(worker) super Core.setup @@ -67,5 +66,7 @@ module Rainbows end end + # :startdoc: + end end diff --git a/lib/rainbows/never_block/event_machine.rb b/lib/rainbows/never_block/event_machine.rb index af72388..0cfaa21 100644 --- a/lib/rainbows/never_block/event_machine.rb +++ b/lib/rainbows/never_block/event_machine.rb @@ -1,3 +1,5 @@ +# -*- encoding: binary -*- +# :enddoc: module Rainbows module NeverBlock class Client < Rainbows::EventMachine::Client diff --git a/lib/rainbows/queue_pool.rb b/lib/rainbows/queue_pool.rb index 806bbee..3ae899c 100644 --- a/lib/rainbows/queue_pool.rb +++ b/lib/rainbows/queue_pool.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: require 'thread' module Rainbows diff --git a/lib/rainbows/response.rb b/lib/rainbows/response.rb index 8d131b0..f42f367 100644 --- a/lib/rainbows/response.rb +++ b/lib/rainbows/response.rb @@ -1,7 +1,7 @@ # -*- encoding: binary -*- +# :enddoc: require 'time' # for Time#httpdate -# :stopdoc: module Rainbows::Response CODES = Unicorn::HttpResponse::CODES @@ -41,4 +41,3 @@ module Rainbows::Response klass.__send__(:include, Rainbows::Response::Body) end end -# :startdoc: diff --git a/lib/rainbows/response/body.rb b/lib/rainbows/response/body.rb index 8d8ec27..e399df7 100644 --- a/lib/rainbows/response/body.rb +++ b/lib/rainbows/response/body.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: # non-portable body response stuff goes here # # The sendfile 1.0.0 RubyGem includes IO#sendfile and diff --git a/lib/rainbows/rev.rb b/lib/rainbows/rev.rb index 6650c2b..6ce073a 100644 --- a/lib/rainbows/rev.rb +++ b/lib/rainbows/rev.rb @@ -25,6 +25,7 @@ module Rainbows module Rev + # :stopdoc: # keep-alive timeout scoreboard KATO = {} @@ -37,5 +38,6 @@ module Rainbows end include Core + # :startdoc: end end diff --git a/lib/rainbows/rev/client.rb b/lib/rainbows/rev/client.rb index 91947b6..d08992b 100644 --- a/lib/rainbows/rev/client.rb +++ b/lib/rainbows/rev/client.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: require 'rainbows/ev_core' module Rainbows module Rev diff --git a/lib/rainbows/rev/core.rb b/lib/rainbows/rev/core.rb index 4668cce..9f7a1f0 100644 --- a/lib/rainbows/rev/core.rb +++ b/lib/rainbows/rev/core.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: require 'rev' Rev::VERSION >= '0.3.0' or abort 'rev >= 0.3.0 is required' require 'rainbows/rev/heartbeat' diff --git a/lib/rainbows/rev/deferred_response.rb b/lib/rainbows/rev/deferred_response.rb index f710b5b..de348bb 100644 --- a/lib/rainbows/rev/deferred_response.rb +++ b/lib/rainbows/rev/deferred_response.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: module Rainbows module Rev diff --git a/lib/rainbows/rev/heartbeat.rb b/lib/rainbows/rev/heartbeat.rb index 54cc056..da1a1e2 100644 --- a/lib/rainbows/rev/heartbeat.rb +++ b/lib/rainbows/rev/heartbeat.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: module Rainbows module Rev diff --git a/lib/rainbows/rev/master.rb b/lib/rainbows/rev/master.rb index 01282f5..40615ac 100644 --- a/lib/rainbows/rev/master.rb +++ b/lib/rainbows/rev/master.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: require 'rainbows/rev' module Rainbows diff --git a/lib/rainbows/rev/sendfile.rb b/lib/rainbows/rev/sendfile.rb index ae0b116..414cfa1 100644 --- a/lib/rainbows/rev/sendfile.rb +++ b/lib/rainbows/rev/sendfile.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: module Rainbows::Rev::Sendfile if IO.method_defined?(:sendfile_nonblock) F = Rainbows::StreamFile diff --git a/lib/rainbows/rev/thread.rb b/lib/rainbows/rev/thread.rb index ba80bb1..8fc7172 100644 --- a/lib/rainbows/rev/thread.rb +++ b/lib/rainbows/rev/thread.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: require 'thread' require 'rainbows/rev/master' diff --git a/lib/rainbows/rev_fiber_spawn.rb b/lib/rainbows/rev_fiber_spawn.rb index e9ea1db..c8e2bd1 100644 --- a/lib/rainbows/rev_fiber_spawn.rb +++ b/lib/rainbows/rev_fiber_spawn.rb @@ -15,7 +15,7 @@ module Rainbows include Base include Fiber::Rev - def worker_loop(worker) + def worker_loop(worker) # :nodoc: Rainbows::Response.setup(Rainbows::Fiber::Rev::Server) init_worker_process(worker) Server.const_set(:MAX, @worker_connections) diff --git a/lib/rainbows/rev_thread_pool.rb b/lib/rainbows/rev_thread_pool.rb index 918b57a..5a7ff82 100644 --- a/lib/rainbows/rev_thread_pool.rb +++ b/lib/rainbows/rev_thread_pool.rb @@ -20,17 +20,19 @@ module Rainbows module RevThreadPool + # :stopdoc: DEFAULTS = { :pool_size => 20, # same default size as ThreadPool (w/o Rev) } + #:startdoc: - def self.setup + def self.setup # :nodoc: DEFAULTS.each { |k,v| O[k] ||= v } Integer === O[:pool_size] && O[:pool_size] > 0 or raise ArgumentError, "pool_size must a be an Integer > 0" end - class PoolWatcher < ::Rev::TimerWatcher + class PoolWatcher < ::Rev::TimerWatcher # :nodoc: all def initialize(threads) @threads = threads super(G.server.timeout, true) @@ -41,7 +43,7 @@ module Rainbows end end - class Client < Rainbows::Rev::ThreadClient + class Client < Rainbows::Rev::ThreadClient # :nodoc: def app_dispatch QUEUE << self end @@ -49,7 +51,7 @@ module Rainbows include Rainbows::Rev::Core - def init_worker_threads(master, queue) + def init_worker_threads(master, queue) # :nodoc: O[:pool_size].times.map do Thread.new do begin @@ -62,7 +64,7 @@ module Rainbows end end - def init_worker_process(worker) + def init_worker_process(worker) # :nodoc: super master = Rev::Master.new(Queue.new).attach(::Rev::Loop.default) queue = Client.const_set(:QUEUE, Queue.new) diff --git a/lib/rainbows/rev_thread_spawn.rb b/lib/rainbows/rev_thread_spawn.rb index 94203f3..68e774b 100644 --- a/lib/rainbows/rev_thread_spawn.rb +++ b/lib/rainbows/rev_thread_spawn.rb @@ -20,7 +20,7 @@ module Rainbows module RevThreadSpawn - class Client < Rainbows::Rev::ThreadClient + class Client < Rainbows::Rev::ThreadClient # :nodoc: all def app_dispatch Thread.new(self) { |client| MASTER << [ client, app_response ] } end @@ -28,7 +28,7 @@ module Rainbows include Rainbows::Rev::Core - def init_worker_process(worker) + def init_worker_process(worker) # :nodoc: super master = Rev::Master.new(Queue.new).attach(::Rev::Loop.default) Client.const_set(:MASTER, master) diff --git a/lib/rainbows/revactor.rb b/lib/rainbows/revactor.rb index de423a3..5a9704d 100644 --- a/lib/rainbows/revactor.rb +++ b/lib/rainbows/revactor.rb @@ -28,7 +28,7 @@ module Rainbows::Revactor # once a client is accepted, it is processed in its entirety here # in 3 easy steps: read request, call app, write app response - def process_client(client) + def process_client(client) # :nodoc: io = client.instance_variable_get(:@_io) io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) rd_args = [ nil ] @@ -72,7 +72,7 @@ module Rainbows::Revactor # runs inside each forked worker, this sits around and waits # for connections and doesn't die until the parent dies (or is # given a INT, QUIT, or TERM signal) - def worker_loop(worker) + def worker_loop(worker) #:nodoc: init_worker_process(worker) self.class.__send__(:alias_method, :write_body, :write_body_each) RD_ARGS[:timeout] = G.kato if G.kato > 0 diff --git a/lib/rainbows/sendfile.rb b/lib/rainbows/sendfile.rb index 3f82047..8d9b46e 100644 --- a/lib/rainbows/sendfile.rb +++ b/lib/rainbows/sendfile.rb @@ -57,7 +57,7 @@ class Sendfile < Struct.new(:app) # Body wrapper, this allows us to fall back gracefully to # +each+ in case a given concurrency model does not optimize # +to_path+ calls. - class Body < Struct.new(:to_path) + class Body < Struct.new(:to_path) # :nodoc: all def self.new(path, headers) unless headers['Content-Length'] @@ -76,7 +76,7 @@ class Sendfile < Struct.new(:app) end end - def call(env) + def call(env) # :nodoc: status, headers, body = app.call(env) headers = HH.new(headers) if path = headers.delete('X-Sendfile') diff --git a/lib/rainbows/tee_input.rb b/lib/rainbows/tee_input.rb index be46cb3..956c68f 100644 --- a/lib/rainbows/tee_input.rb +++ b/lib/rainbows/tee_input.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# :enddoc: module Rainbows # acts like tee(1) on an input input to provide a input-like stream diff --git a/lib/rainbows/thread_pool.rb b/lib/rainbows/thread_pool.rb index f609483..28a943e 100644 --- a/lib/rainbows/thread_pool.rb +++ b/lib/rainbows/thread_pool.rb @@ -25,7 +25,7 @@ module Rainbows include Base - def worker_loop(worker) + def worker_loop(worker) # :nodoc: init_worker_process(worker) pool = (1..worker_connections).map do Thread.new { LISTENERS.size == 1 ? sync_worker : async_worker } @@ -41,7 +41,7 @@ module Rainbows join_threads(pool) end - def sync_worker + def sync_worker # :nodoc: s = LISTENERS[0] begin c = Rainbows.sync_accept(s) and process_client(c) @@ -50,7 +50,7 @@ module Rainbows end while G.alive end - def async_worker + def async_worker # :nodoc: begin # TODO: check if select() or accept() is a problem on large # SMP systems under Ruby 1.9. Hundreds of native threads @@ -66,7 +66,7 @@ module Rainbows end while G.alive end - def join_threads(threads) + def join_threads(threads) # :nodoc: G.quit! threads.delete_if do |thr| G.tick diff --git a/lib/rainbows/thread_spawn.rb b/lib/rainbows/thread_spawn.rb index 9660fc0..6952f26 100644 --- a/lib/rainbows/thread_spawn.rb +++ b/lib/rainbows/thread_spawn.rb @@ -17,10 +17,9 @@ module Rainbows # capabilities module ThreadSpawn - include Base - def accept_loop(klass) + def accept_loop(klass) #:nodoc: lock = Mutex.new limit = worker_connections LISTENERS.each do |l| @@ -55,7 +54,7 @@ module Rainbows sleep 1 while G.tick || lock.synchronize { G.cur > 0 } end - def worker_loop(worker) + def worker_loop(worker) #:nodoc: init_worker_process(worker) accept_loop(Thread) end diff --git a/lib/rainbows/writer_thread_pool.rb b/lib/rainbows/writer_thread_pool.rb index 84b750b..4050af9 100644 --- a/lib/rainbows/writer_thread_pool.rb +++ b/lib/rainbows/writer_thread_pool.rb @@ -24,7 +24,7 @@ module Rainbows # used to wrap a BasicSocket to use with +q+ for all writes # this is compatible with IO.select - class QueueSocket < Struct.new(:to_io, :q) + class QueueSocket < Struct.new(:to_io, :q) # :nodoc: def readpartial(size, buf = "") to_io.readpartial(size, buf) end @@ -46,7 +46,7 @@ module Rainbows end end - module Response + module Response # :nodoc: def write_body(qclient, body) qclient.q << [ qclient.to_io, :body, body ] end @@ -55,12 +55,12 @@ module Rainbows @@nr = 0 @@q = nil - def process_client(client) + def process_client(client) # :nodoc: @@nr += 1 super(QueueSocket[client, @@q[@@nr %= @@q.size]]) end - def worker_loop(worker) + def worker_loop(worker) # :nodoc: Rainbows::Response.setup(self.class) self.class.__send__(:alias_method, :sync_write_body, :write_body) self.class.__send__(:include, Response) diff --git a/lib/rainbows/writer_thread_spawn.rb b/lib/rainbows/writer_thread_spawn.rb index b9bbad2..cbe7765 100644 --- a/lib/rainbows/writer_thread_spawn.rb +++ b/lib/rainbows/writer_thread_spawn.rb @@ -23,11 +23,11 @@ module Rainbows module WriterThreadSpawn include Base - CUR = {} + CUR = {} # :nodoc: # used to wrap a BasicSocket to use with +q+ for all writes # this is compatible with IO.select - class MySocket < Struct.new(:to_io, :q, :thr) + class MySocket < Struct.new(:to_io, :q, :thr) # :nodoc: all include Rainbows::Response def readpartial(size, buf = "") @@ -90,15 +90,15 @@ module Rainbows end end - def write_body(my_sock, body) + def write_body(my_sock, body) # :nodoc: my_sock.queue_body(body) end - def process_client(client) + def process_client(client) # :nodoc: super(MySocket[client]) end - def worker_loop(worker) + def worker_loop(worker) # :nodoc: MySocket.const_set(:MAX, worker_connections) Rainbows::Response.setup(MySocket) super(worker) # accept loop from Unicorn |