Class: Yahns::StreamFile
- Inherits:
-
Object
- Object
- Yahns::StreamFile
- Includes:
- WbufCommon
- Defined in:
- lib/yahns/stream_file.rb
Overview
:nodoc:
Constant Summary collapse
- NeedClose =
do not use this in your app (or any of our API)
Class.new(File)
Instance Method Summary collapse
-
#initialize(body, persist, offset, count) ⇒ StreamFile
constructor
A new instance of StreamFile.
-
#wbuf_close(client) ⇒ Object
called by last wbuf_flush.
Methods included from WbufCommon
#wbuf_close_common, #wbuf_flush
Constructor Details
#initialize(body, persist, offset, count) ⇒ StreamFile
Returns a new instance of StreamFile.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/yahns/stream_file.rb', line 12 def initialize(body, persist, offset, count) if body.respond_to?(:to_io) @tmpio = body.to_io else path = body.to_path if path =~ %r{\A/dev/fd/(\d+)\z} @tmpio = IO.for_fd($1.to_i) @tmpio.autoclose = false else retried = false begin @tmpio = NeedClose.open(path) rescue Errno::EMFILE, Errno::ENFILE raise if retried retried = true Thread.current[:yahns_fdmap].desperate_expire(5) sleep(1) retry end end end @sf_offset = offset @sf_count = count || @tmpio.stat.size @wbuf_persist = persist # whether or not we keep the connection alive @body = body end |
Instance Method Details
#wbuf_close(client) ⇒ Object
called by last wbuf_flush
40 41 42 43 |
# File 'lib/yahns/stream_file.rb', line 40 def wbuf_close(client) @tmpio.close if NeedClose === @tmpio wbuf_close_common(client) end |