about summary refs log tree commit homepage
path: root/lib/rainbows
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-08-05 18:44:32 +0000
committerEric Wong <normalperson@yhbt.net>2011-08-05 18:44:32 +0000
commit7223b868624d19f3421045c2bc5b075bacd83694 (patch)
tree2a3d5817dfbb84bbf0a4738d518572f3810c801a /lib/rainbows
parentc6bb07a6475f71dc1e2b46b87a34fbbf46c52b5d (diff)
downloadrainbows-7223b868624d19f3421045c2bc5b075bacd83694.tar.gz
This can allow Cramp (and potentially other libraries)
to subclass or implement duck-type compatible versions
of Rainbows::EventMachine::Client.
Diffstat (limited to 'lib/rainbows')
-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)