summary refs log tree commit homepage
path: root/lib/rainbows/event_machine.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rainbows/event_machine.rb')
-rw-r--r--lib/rainbows/event_machine.rb17
1 files changed, 16 insertions, 1 deletions
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)