rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob 08a9c2dd85cf8b7714783aac20f3e5b96e5af067 637 bytes (raw)
$ git show HEAD:lib/rainbows/stream_file.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
 
# -*- encoding: binary -*-
# :enddoc:

# Used to keep track of file offsets in IO#trysendfile + evented
# models.  We always maintain our own file offsets in userspace because
# because sendfile() implementations offer pread()-like idempotency for
# concurrency (multiple clients can read the same underlying file handle).
class Rainbows::StreamFile
  attr_reader :to_io
  attr_accessor :offset, :count

  def initialize(offset, count, io, body)
    @offset, @count, @to_io, @body = offset, count, io, body
  end

  def close
    @body.close if @body.respond_to?(:close)
    @to_io.close unless @to_io.closed?
    @to_io = nil
  end
end

git clone https://yhbt.net/rainbows.git