From 7223b868624d19f3421045c2bc5b075bacd83694 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 5 Aug 2011 18:44:32 +0000 Subject: event_machine: add :em_client_class option This can allow Cramp (and potentially other libraries) to subclass or implement duck-type compatible versions of Rainbows::EventMachine::Client. --- lib/rainbows/event_machine.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb index fb7177b..64f61da 100644 --- a/lib/rainbows/event_machine.rb +++ b/lib/rainbows/event_machine.rb @@ -50,6 +50,21 @@ module Rainbows::EventMachine include Rainbows::Base + # Cramp (and possibly others) can subclass Rainbows::EventMachine::Client + # and provide the :em_client_class option. We /don't/ want to load + # Rainbows::EventMachine::Client in the master process since we need + # reloadability. + def em_client_class + case klass = Rainbows::O[:em_client_class] + when Proc + klass.call # e.g.: proc { Cramp::WebSocket::Rainbows } + when Symbol, String + eval(klass.to_s) # Object.const_get won't resolve multi-level paths + else # @use should be either :EventMachine or :NeverBlock + Rainbows.const_get(@use).const_get(:Client) + end + end + # 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) @@ -63,7 +78,7 @@ module Rainbows::EventMachine EM.epoll EM.kqueue logger.info "#@use: epoll=#{EM.epoll?} kqueue=#{EM.kqueue?}" - client_class = Rainbows.const_get(@use).const_get(:Client) + client_class = em_client_class max = worker_connections + LISTENERS.size Rainbows::EventMachine::Server.const_set(:MAX, max) Rainbows::EventMachine::Server.const_set(:CL, client_class) -- cgit v1.2.3-24-ge0c7