diff options
Diffstat (limited to 'lib/rainbows/fiber/body.rb')
-rw-r--r-- | lib/rainbows/fiber/body.rb | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/rainbows/fiber/body.rb b/lib/rainbows/fiber/body.rb index 872b1df..5b2c74b 100644 --- a/lib/rainbows/fiber/body.rb +++ b/lib/rainbows/fiber/body.rb @@ -5,19 +5,20 @@ # 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 |