From 7d07c36f1da30af054d78deed5e87f29832d6f6b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 7 Nov 2009 20:09:50 -0800 Subject: ev_core: cleanup handling of APP constant It'll make development of future ev_core-derived things easier, hopefully. --- lib/rainbows/ev_core.rb | 4 ++++ lib/rainbows/event_machine.rb | 2 +- lib/rainbows/rev/client.rb | 2 -- lib/rainbows/rev/core.rb | 8 ++++---- 4 files changed, 9 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/rainbows/ev_core.rb b/lib/rainbows/ev_core.rb index 244e726..017fe5c 100644 --- a/lib/rainbows/ev_core.rb +++ b/lib/rainbows/ev_core.rb @@ -8,6 +8,10 @@ module Rainbows include Rainbows::Const G = Rainbows::G + def self.setup(klass) + klass.const_set(:APP, G.server.app) + end + def post_init @remote_addr = ::TCPSocket === @_io ? @_io.peeraddr.last : LOCALHOST @env = {} diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb index 7f77428..76085dc 100644 --- a/lib/rainbows/event_machine.rb +++ b/lib/rainbows/event_machine.rb @@ -191,9 +191,9 @@ module Rainbows EM.epoll EM.kqueue logger.info "EventMachine: epoll=#{EM.epoll?} kqueue=#{EM.kqueue?}" - Client.const_set(:APP, G.server.app) Server.const_set(:MAX, G.server.worker_connections + HttpServer::LISTENERS.size) + EvCore.setup(Client) EM.run { conns = EM.instance_variable_get(:@conns) or raise RuntimeError, "EM @conns instance variable not accessible!" diff --git a/lib/rainbows/rev/client.rb b/lib/rainbows/rev/client.rb index c9d058e..52ddaab 100644 --- a/lib/rainbows/rev/client.rb +++ b/lib/rainbows/rev/client.rb @@ -3,8 +3,6 @@ require 'rainbows/ev_core' module Rainbows module Rev - include Base - class Client < ::Rev::IO include Rainbows::EvCore G = Rainbows::G diff --git a/lib/rainbows/rev/core.rb b/lib/rainbows/rev/core.rb index 0d1add5..0460137 100644 --- a/lib/rainbows/rev/core.rb +++ b/lib/rainbows/rev/core.rb @@ -20,6 +20,7 @@ module Rainbows 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 @@ -27,10 +28,9 @@ module Rainbows def worker_loop(worker) init_worker_process(worker) mod = self.class.const_get(@use) - client = mod.const_get(:Client) - client.const_set(:APP, G.server.app) - Server.const_set(:MAX, G.server.worker_connections) - Server.const_set(:CL, client) + Server.const_set(:MAX, @worker_connections) + Server.const_set(:CL, mod.const_get(:Client)) + EvCore.setup(EvCore) rloop = ::Rev::Loop.default Heartbeat.new(1, true).attach(rloop) LISTENERS.map! { |s| Server.new(s).attach(rloop) } -- cgit v1.2.3-24-ge0c7