summary refs log tree commit homepage
path: root/lib/rainbows/dev_fd_response.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-08-17 08:35:03 +0000
committerEric Wong <normalperson@yhbt.net>2010-08-17 08:41:15 +0000
commitac05e7035e1946b78ce4679548db7680aa01734c (patch)
tree1379997b2686b9fa777216ad06f1ffe9be5b6027 /lib/rainbows/dev_fd_response.rb
parent9c5669e232f8f57c2d8e08d84e21bf09cd87bfa1 (diff)
First off we use an FD_MAP to avoid creating redundant IO
objects which map to the same FD.  When that doesn't work, we'll
fall back to trapping Errno::EBADF and IOError where
appropriate.
Diffstat (limited to 'lib/rainbows/dev_fd_response.rb')
-rw-r--r--lib/rainbows/dev_fd_response.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/rainbows/dev_fd_response.rb b/lib/rainbows/dev_fd_response.rb
index 637bcc2..7f70b8e 100644
--- a/lib/rainbows/dev_fd_response.rb
+++ b/lib/rainbows/dev_fd_response.rb
@@ -14,7 +14,8 @@
 class Rainbows::DevFdResponse < Struct.new(:app)
 
   # :stopdoc:
-  #
+  FD_MAP = Rainbows::FD_MAP
+
   # make this a no-op under Rubinius, it's pointless anyways
   # since Rubinius doesn't have IO.copy_stream
   def self.new(app)
@@ -37,6 +38,7 @@ class Rainbows::DevFdResponse < Struct.new(:app)
     headers = HeaderHash.new(headers)
     st = io.stat
     fileno = io.fileno
+    FD_MAP[fileno] = io
     if st.file?
       headers['Content-Length'] ||= st.size.to_s
       headers.delete('Transfer-Encoding')