stream_file: hide internals
[rainbows.git] / lib / rainbows / stream_file.rb
blob08a9c2dd85cf8b7714783aac20f3e5b96e5af067
1 # -*- encoding: binary -*-
2 # :enddoc:
4 # Used to keep track of file offsets in IO#trysendfile + evented
5 # models.  We always maintain our own file offsets in userspace because
6 # because sendfile() implementations offer pread()-like idempotency for
7 # concurrency (multiple clients can read the same underlying file handle).
8 class Rainbows::StreamFile
9   attr_reader :to_io
10   attr_accessor :offset, :count
12   def initialize(offset, count, io, body)
13     @offset, @count, @to_io, @body = offset, count, io, body
14   end
16   def close
17     @body.close if @body.respond_to?(:close)
18     @to_io.close unless @to_io.closed?
19     @to_io = nil
20   end
21 end