about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/yahns/stream_file.rb9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/yahns/stream_file.rb b/lib/yahns/stream_file.rb
index a7f47ac..03dab45 100644
--- a/lib/yahns/stream_file.rb
+++ b/lib/yahns/stream_file.rb
@@ -6,6 +6,9 @@ require_relative 'wbuf_common'
 class Yahns::StreamFile # :nodoc:
   include Yahns::WbufCommon
 
+  # do not use this in your app (or any of our API)
+  NeedClose = Class.new(File) # :nodoc:
+
   def initialize(body, persist, offset, count)
     if body.respond_to?(:to_io)
       @tmpio = body.to_io
@@ -17,7 +20,7 @@ class Yahns::StreamFile # :nodoc:
       else
         retried = false
         begin
-          @tmpio = File.open(path)
+          @tmpio = NeedClose.open(path)
         rescue Errno::EMFILE, Errno::ENFILE
           raise if retried
           retried = true
@@ -35,9 +38,7 @@ class Yahns::StreamFile # :nodoc:
 
   # called by last wbuf_flush
   def wbuf_close(client)
-    if File === @tmpio && @tmpio != @body
-      @tmpio.close
-    end
+    @tmpio.close if NeedClose === @tmpio
     wbuf_close_common(client)
   end
 end