summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-06-27 15:58:45 -0700
committerEric Wong <normalperson@yhbt.net>2009-06-29 04:04:27 -0700
commit14ce889cc12628405b0f6a1842b7e1ad09ca4b7b (patch)
tree2188c1bdb823209bd6bfaeeda249af74f99b7920
parent665717d9d339748447e26d3eb0e34c9f6c64ce73 (diff)
The complexity of making the object persistent isn't worth the
potential performance gain here.
-rw-r--r--lib/unicorn.rb2
-rw-r--r--lib/unicorn/http_request.rb3
-rw-r--r--lib/unicorn/tee_input.rb24
3 files changed, 7 insertions, 22 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index 13da564..343f762 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -1,4 +1,5 @@
 require 'fcntl'
+require 'tempfile'
 require 'unicorn/socket_helper'
 autoload :Rack, 'rack'
 
@@ -471,7 +472,6 @@ module Unicorn
       worker.tempfile.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
       @after_fork.call(self, worker) # can drop perms
       @timeout /= 2.0 # halve it for select()
-      HttpRequest::TEE.setup
       build_app! unless @preload_app
     end
 
diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb
index d9cb8b2..e25517b 100644
--- a/lib/unicorn/http_request.rb
+++ b/lib/unicorn/http_request.rb
@@ -27,7 +27,6 @@ module Unicorn
     }
 
     NULL_IO = StringIO.new(Z)
-    TEE = TeeInput.new
     DECHUNKER = ChunkedReader.new
     LOCALHOST = '127.0.0.1'.freeze
 
@@ -104,7 +103,7 @@ module Unicorn
           end
         end
 
-        inp = TEE.reopen(socket, length, body)
+        inp = TeeInput.new(socket, length, body)
         DEFAULTS[Const::STREAM_INPUT] ? inp : inp.consume
       else
         NULL_IO.closed? ? NULL_IO.reopen(Z) : NULL_IO
diff --git a/lib/unicorn/tee_input.rb b/lib/unicorn/tee_input.rb
index 9e66837..ac9638d 100644
--- a/lib/unicorn/tee_input.rb
+++ b/lib/unicorn/tee_input.rb
@@ -15,30 +15,16 @@ require 'tempfile'
 module Unicorn
   class TeeInput
 
-    def initialize
-      @rd = @wr = @size = @input = nil
-      setup
-    end
-
-    def setup
-      @tmp = tmp = Tempfile.new(nil)
-      @rd.close if @rd
-      @rd = File.open(tmp.path, 'wb+')
-      @wr.close if @wr
-      @wr = File.open(tmp.path, 'wb')
+    def initialize(input, size = nil, buffer = nil)
+      @wr = Tempfile.new(nil)
+      @wr.binmode
+      @rd = File.open(@wr.path, 'rb')
+      @wr.unlink
       @rd.sync = @wr.sync = true
 
-      tmp.close!
-    end
-
-    def reopen(input, size = nil, buffer = nil)
-      @rd.seek(0)
-      @wr.seek(0)
-      @rd.truncate(0) # truncate read to flush luserspace read buffers
       @wr.write(buffer) if buffer
       @input = input
       @size = size # nil if chunked
-      self
     end
 
     def consume