Module: Yahns::SendfileCompat

Defined in:
lib/yahns/sendfile_compat.rb

Overview

Copyright © 2013-2016 all contributors <[email protected]> License: GPL-3.0+ (www.gnu.org/licenses/gpl-3.0.txt) frozen_string_literal: true

Instance Method Summary collapse

Instance Method Details

#trysendfile(io, offset, count) ⇒ Object

:nodoc:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/yahns/sendfile_compat.rb', line 7

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