about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-08-18 15:22:56 -0700
committerEric Wong <normalperson@yhbt.net>2009-08-18 15:22:56 -0700
commitfd763aa5633724de9e5c580f27ea61850a58d9b8 (patch)
tree05a7e13b2af1ea90cae46d73c189a050b1708030
parentc286192991f072af355081e88abaefb4e8293965 (diff)
downloadunicorn-fd763aa5633724de9e5c580f27ea61850a58d9b8.tar.gz
So we can reuse our existing TCPServer objects.  Patches have
already been submitted (but not yet accepted) to rev for
upstream inclusion here:

  http://rubyforge.org/pipermail/rev-talk/2009-August/000097.html
-rw-r--r--lib/unicorn/rainbows.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/unicorn/rainbows.rb b/lib/unicorn/rainbows.rb
index 39fe29c..6c9a0d6 100644
--- a/lib/unicorn/rainbows.rb
+++ b/lib/unicorn/rainbows.rb
@@ -92,6 +92,27 @@ module Unicorn
   end
 end
 
+# Allow Rev::TCPListener to use an existing TCPServer
+# patch already submitted:
+#   http://rubyforge.org/pipermail/rev-talk/2009-August/000097.html
+class Rev::TCPListener
+  alias_method :orig_initialize, :initialize
+
+  def initialize(addr, port = nil, options = {})
+    BasicSocket.do_not_reverse_lookup = true unless options[:reverse_lookup]
+    options[:backlog] ||= DEFAULT_BACKLOG
+
+    listen_socket = if ::TCPServer === addr
+      addr
+    else
+      raise ArgumentError, "port must be an integer" if nil == port
+      ::TCPServer.new(addr, port)
+    end
+    listen_socket.instance_eval { listen(options[:backlog]) }
+    super(listen_socket)
+  end
+end
+
 if $0 == __FILE__
   app = lambda { |env|
     if /\A100-continue\z/i =~ env['HTTP_EXPECT']