From cd8a874d18fe01e11bb57b91186b6c9f712a4b3f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 10 Mar 2011 15:06:10 -0800 Subject: switch from IO#sendfile_nonblock to IO#trysendfile 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. --- lib/rainbows/epoll/client.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib/rainbows/epoll/client.rb') diff --git a/lib/rainbows/epoll/client.rb b/lib/rainbows/epoll/client.rb index a243d5d..b7b0c9e 100644 --- a/lib/rainbows/epoll/client.rb +++ b/lib/rainbows/epoll/client.rb @@ -183,15 +183,16 @@ module Rainbows::Epoll::Client # returns +nil+ on EOF, :wait_writable if the client blocks def stream_file(sf) # +sf+ is a Rainbows::StreamFile object - begin - sf.offset += (n = sendfile_nonblock(sf, sf.offset, sf.count)) + case n = trysendfile(sf, sf.offset, sf.count) + when Integer + sf.offset += n 0 == (sf.count -= n) and return sf.close - rescue Errno::EAGAIN - return :wait_writable + else + return n # :wait_writable or nil + end while true rescue sf.close raise - end while true end def defer_file_stream(offset, count, io, body) -- cgit v1.2.3-24-ge0c7