about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-05-07 21:43:43 +0000
committerEric Wong <e@80x24.org>2015-05-16 21:25:13 +0000
commit7c88e3e0f4cbfdbc077946b427884311ca314304 (patch)
treeef39e3faa397ad3f19771da46bd574a7f75893c1
parentfdf09e562733f9509d275cb13c1c1a04e579a68a (diff)
downloadunicorn-7c88e3e0f4cbfdbc077946b427884311ca314304.tar.gz
proc creation is expensive, so merely use a 48-byte generic ivar
hash slot for @socket instead.
-rw-r--r--lib/unicorn/http_request.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb
index b32003e..b60e383 100644
--- a/lib/unicorn/http_request.rb
+++ b/lib/unicorn/http_request.rb
@@ -97,15 +97,21 @@ class Unicorn::HttpParser
 
     e[RACK_INPUT] = 0 == content_length ?
                     NULL_IO : @@input_class.new(socket, self)
-    hijack_setup(e, socket)
+
+    # for Rack hijacking in Rack 1.5 and later
+    @socket = socket
+    e[RACK_HIJACK] = self
+
     e.merge!(DEFAULTS)
   end
 
-  def hijacked?
-    env.include?(RACK_HIJACK_IO)
+  # for rack.hijack, we respond to this method so no extra allocation
+  # of a proc object
+  def call
+    env[RACK_HIJACK_IO] = @socket
   end
 
-  def hijack_setup(e, socket)
-    e[RACK_HIJACK] = proc { e[RACK_HIJACK_IO] = socket }
+  def hijacked?
+    env.include?(RACK_HIJACK_IO)
   end
 end