about summary refs log tree commit homepage
path: root/lib/unicorn/util.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-11-05 00:49:06 -0800
committerEric Wong <normalperson@yhbt.net>2009-11-05 00:49:06 -0800
commitd3c20360f9607a9e04f7d28ce0a796437f733e5f (patch)
tree19783fd6009bef38ae57e8aa5b31360505ba25cd /lib/unicorn/util.rb
parentc59dad8b8cca7087860e64d161250ab09edb14e9 (diff)
downloadunicorn-d3c20360f9607a9e04f7d28ce0a796437f733e5f.tar.gz
Subclass off the core File class so we don't have to
worry about #size being defined.  This will mainly
be useful to Rainbows! but allows us to simplify
our TeeInput implementation a little, too.
Diffstat (limited to 'lib/unicorn/util.rb')
-rw-r--r--lib/unicorn/util.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/unicorn/util.rb b/lib/unicorn/util.rb
index 4bbc590..6444699 100644
--- a/lib/unicorn/util.rb
+++ b/lib/unicorn/util.rb
@@ -4,6 +4,16 @@ require 'fcntl'
 require 'tmpdir'
 
 module Unicorn
+
+  class TmpIO < ::File
+
+    # for easier env["rack.input"] compatibility
+    def size
+      # flush if sync
+      stat.size
+    end
+  end
+
   class Util
     class << self
 
@@ -47,8 +57,8 @@ module Unicorn
       # buffering is disabled
       def tmpio
         fp = begin
-          File.open("#{Dir::tmpdir}/#{rand}",
-                    File::RDWR|File::CREAT|File::EXCL, 0600)
+          TmpIO.open("#{Dir::tmpdir}/#{rand}",
+                     File::RDWR|File::CREAT|File::EXCL, 0600)
         rescue Errno::EEXIST
           retry
         end