lib/rainbows/fiber/body.rb in rainbows-3.1.0 vs lib/rainbows/fiber/body.rb in rainbows-3.2.0
- old
+ new
@@ -3,22 +3,23 @@
# non-portable body handling for Fiber-based concurrency goes here
# this module is required and included in worker processes only
# this is meant to be included _after_ Rainbows::Response::Body
module Rainbows::Fiber::Body # :nodoc:
- # the sendfile 1.0.0+ gem includes IO#sendfile_nonblock
- if IO.method_defined?(:sendfile_nonblock)
+ # the sendfile 1.1.0+ gem includes IO#trysendfile
+ if IO.method_defined?(:trysendfile)
def write_body_file(body, range)
sock, n, body = to_io, nil, body_to_io(body)
offset, count = range ? range : [ 0, body.stat.size ]
- begin
- offset += (n = sock.sendfile_nonblock(body, offset, count))
- rescue Errno::EAGAIN
+ case n = sock.trysendfile(body, offset, count)
+ when Integer
+ offset += n
+ return if 0 == (count -= n)
+ when :wait_writable
kgio_wait_writable
- retry
- rescue EOFError
- break
- end while (count -= n) > 0
+ else # nil
+ return
+ end while true
ensure
close_if_private(body)
end
end