yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
cdd2d7bd1854007d7e48712edf40a858df16b739 blob 786 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
# -*- 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

class IO # :nodoc:
  include Yahns::SendfileCompat
end
debug log:

solving cdd2d7b ...
found cdd2d7b in https://yhbt.net/yahns.git

Code repositories for project(s) associated with this inbox:

	../../../yahns.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).