Sha256: 4d5a0c08d791296bc65aebb46e6d7807f5e78038ac87d304fae990d5a9d465cf

Contents?: true

Size: 730 Bytes

Versions: 6

Compression:

Stored size: 730 Bytes

Contents

# -*- encoding: binary -*-
# Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
# License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
# frozen_string_literal: true

module Yahns::SendfileCompat # :nodoc:
  def trysendfile(io, offset, count)
    return 0 if count == 0
    count = 0x4000 if count > 0x4000
    buf = Thread.current[:yahns_sfbuf] ||= ''.dup
    io.pos = offset
    str = io.read(count, buf) or return # nil for EOF
    n = 0
    case rv = kgio_trywrite(str)
    when String # partial write, keep trying
      n += (str.size - rv.size)
      str = rv
    when :wait_writable, :wait_readable
      return n > 0 ? n : rv
    when nil
      return n + str.size # yay!
    end while true
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
yahns-1.12.5 lib/yahns/sendfile_compat.rb
yahns-1.12.4 lib/yahns/sendfile_compat.rb
yahns-1.12.3 lib/yahns/sendfile_compat.rb
yahns-1.12.2 lib/yahns/sendfile_compat.rb
yahns-1.12.1 lib/yahns/sendfile_compat.rb
yahns-1.12.0 lib/yahns/sendfile_compat.rb