diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-03-10 15:06:10 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-03-10 15:06:10 -0800 |
commit | cd8a874d18fe01e11bb57b91186b6c9f712a4b3f (patch) | |
tree | a8400f2e6eeca1a4d4a686e138b97eb831eb9a8d /lib/rainbows/fiber | |
parent | afea5cd7c691de95b37d29728ab4880e3b737a42 (diff) | |
download | rainbows-cd8a874d18fe01e11bb57b91186b6c9f712a4b3f.tar.gz |
IO#trysendfile does not raise exceptions for common EAGAIN errors, making it far less expensive to use with the following concurrency models: * Coolio * CoolioFiberSpawn * Revactor * FiberSpawn * FiberPool This requires the new sendfile 1.1.0 RubyGem and removes support for the sendfile 1.0.0. All sendfile users must upgrade or be left without sendfile(2) support. IO#sendfile behaves the same if you're using a multi-threaded concurrency option, but we don't detect nor use it unless IO#trysendfile exists.
Diffstat (limited to 'lib/rainbows/fiber')
-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 |