From 68accc9930b0653b702553790d4ccd626a8dfdfe Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 26 Dec 2010 03:09:47 +0000 Subject: rev: split out Rainbows::Rev::Server One file per class/module should be easier for new hackers to find. Unindent rainbows/rev/core while we're at it, too. --- lib/rainbows/rev.rb | 9 ++++--- lib/rainbows/rev/core.rb | 58 ++++++++++++++++++---------------------------- lib/rainbows/rev/server.rb | 11 +++++++++ 3 files changed, 37 insertions(+), 41 deletions(-) create mode 100644 lib/rainbows/rev/server.rb diff --git a/lib/rainbows/rev.rb b/lib/rainbows/rev.rb index 71bcfcc..47ee17f 100644 --- a/lib/rainbows/rev.rb +++ b/lib/rainbows/rev.rb @@ -1,6 +1,4 @@ # -*- encoding: binary -*- -require 'rainbows/rev/core' -require 'rainbows/rev/client' # Implements a basic single-threaded event model with # {Rev}[http://rev.rubyforge.org/]. It is capable of handling @@ -21,7 +19,6 @@ require 'rainbows/rev/client' # temporary file before the application is entered. module Rainbows::Rev - # :stopdoc: # keep-alive timeout scoreboard KATO = {} @@ -33,9 +30,11 @@ module Rainbows::Rev CONN.compare_by_identity KATO.compare_by_identity end - - include Rainbows::Rev::Core # :startdoc: end +# :enddoc: +require 'rainbows/rev/core' +require 'rainbows/rev/client' +Rainbows::Rev.__send__ :include, Rainbows::Rev::Core require 'rainbows/rev/deferred_response' require 'rainbows/rev/deferred_chunk_response' diff --git a/lib/rainbows/rev/core.rb b/lib/rainbows/rev/core.rb index 5c5b799..78d9601 100644 --- a/lib/rainbows/rev/core.rb +++ b/lib/rainbows/rev/core.rb @@ -3,40 +3,26 @@ require 'rev' Rev::VERSION >= '0.3.0' or abort 'rev >= 0.3.0 is required' require 'rainbows/rev/heartbeat' +require 'rainbows/rev/server' +module Rainbows::Rev::Core + include Rainbows::Base -module Rainbows - module Rev - class Server < ::Rev::IO - # CL and MAX will be defined in the corresponding worker loop - - def on_readable - return if CONN.size >= MAX - io = @_io.kgio_tryaccept and CL.new(io).attach(LOOP) - end - end # class Server - - module Core - include Base - - # 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) - Rainbows::Response.setup(Rainbows::Rev::Client) - require 'rainbows/rev/sendfile' - Rainbows::Rev::Client.__send__(:include, Rainbows::Rev::Sendfile) - init_worker_process(worker) - mod = Rainbows.const_get(@use) - rloop = Server.const_set(:LOOP, ::Rev::Loop.default) - Server.const_set(:MAX, @worker_connections) - Server.const_set(:CL, mod.const_get(:Client)) - EvCore.const_set(:APP, G.server.app) - Rainbows::EvCore.setup - Heartbeat.new(1, true).attach(rloop) - LISTENERS.map! { |s| Server.new(s).attach(rloop) } - rloop.run - end - - end # module Core - end # module Rev -end # 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) + Rainbows::Response.setup(Rainbows::Rev::Client) + require 'rainbows/rev/sendfile' + Rainbows::Rev::Client.__send__(:include, Rainbows::Rev::Sendfile) + init_worker_process(worker) + mod = Rainbows.const_get(@use) + rloop = Rainbows::Rev::Server.const_set(:LOOP, ::Rev::Loop.default) + Rainbows::Rev::Server.const_set(:MAX, @worker_connections) + Rainbows::Rev::Server.const_set(:CL, mod.const_get(:Client)) + Rainbows::EvCore.const_set(:APP, G.server.app) + Rainbows::EvCore.setup + Rainbows::Rev::Heartbeat.new(1, true).attach(rloop) + LISTENERS.map! { |s| Rainbows::Rev::Server.new(s).attach(rloop) } + rloop.run + end +end diff --git a/lib/rainbows/rev/server.rb b/lib/rainbows/rev/server.rb new file mode 100644 index 0000000..7363b5c --- /dev/null +++ b/lib/rainbows/rev/server.rb @@ -0,0 +1,11 @@ +# -*- encoding: binary -*- +# :enddoc: +class Rainbows::Rev::Server < ::Rev::IO + CONN = Rainbows::Rev::CONN + # CL and MAX will be defined in the corresponding worker loop + + def on_readable + return if CONN.size >= MAX + io = @_io.kgio_tryaccept and CL.new(io).attach(LOOP) + end +end -- cgit v1.2.3-24-ge0c7