From c4996358a9cd949757f297dfdcc2a71306fc285f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 6 Dec 2009 13:03:30 -0800 Subject: EventMachine: allow usage as a base class We'll be adding EventMachine-based concurrency models. --- lib/rainbows/event_machine.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb index 2fa18f1..e81914a 100644 --- a/lib/rainbows/event_machine.rb +++ b/lib/rainbows/event_machine.rb @@ -173,7 +173,7 @@ module Rainbows return if CUR.size >= MAX io = Rainbows.accept(@io) or return sig = EM.attach_fd(io.fileno, false) - CUR[sig] = Client.new(sig, io) + CUR[sig] = CL.new(sig, io) end end @@ -186,16 +186,18 @@ module Rainbows # enable them both, should be non-fatal if not supported EM.epoll EM.kqueue - logger.info "EventMachine: epoll=#{EM.epoll?} kqueue=#{EM.kqueue?}" + logger.info "#@use: epoll=#{EM.epoll?} kqueue=#{EM.kqueue?}" + client_class = Rainbows.const_get(@use).const_get(:Client) Server.const_set(:MAX, worker_connections + LISTENERS.size) - EvCore.setup(Client) + Server.const_set(:CL, client_class) + EvCore.setup(client_class) EM.run { conns = EM.instance_variable_get(:@conns) or raise RuntimeError, "EM @conns instance variable not accessible!" Server.const_set(:CUR, conns) EM.add_periodic_timer(1) do unless G.tick - conns.each_value { |client| Client === client and client.quit } + conns.each_value { |c| client_class === c and c.quit } EM.stop if conns.empty? && EM.reactor_running? end end -- cgit v1.2.3-24-ge0c7