lib/rainbows/revactor/client/methods.rb in rainbows-3.1.0 vs lib/rainbows/revactor/client/methods.rb in rainbows-3.2.0
- old
+ new
@@ -1,31 +1,32 @@
# -*- encoding: binary -*-
# :enddoc:
module Rainbows::Revactor::Client::Methods
- if IO.method_defined?(:sendfile_nonblock)
+ if IO.method_defined?(:trysendfile)
def write_body_file(body, range)
body, client = body_to_io(body), @client
sock = @client.instance_variable_get(:@_io)
pfx = Revactor::TCP::Socket === client ? :tcp : :unix
write_complete = T[:"#{pfx}_write_complete", client]
closed = T[:"#{pfx}_closed", client]
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
# The @_write_buffer is empty at this point, trigger the
# on_readable method which in turn triggers on_write_complete
# even though nothing was written
client.controller = Actor.current
client.__send__(:enable_write_watcher)
Actor.receive do |filter|
filter.when(write_complete) {}
filter.when(closed) { raise Errno::EPIPE }
end
- retry
- rescue EOFError
- break
- end while (count -= n) > 0
+ else # nil
+ return
+ end while true
ensure
close_if_private(body)
end
end