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/response.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/rainbows/response.rb') diff --git a/lib/rainbows/response.rb b/lib/rainbows/response.rb index 2c517f8..576ff8d 100644 --- a/lib/rainbows/response.rb +++ b/lib/rainbows/response.rb @@ -67,7 +67,7 @@ module Rainbows::Response end # generic response writer, used for most dynamically-generated responses - # and also when IO.copy_stream and/or IO#sendfile_nonblock is unavailable + # and also when IO.copy_stream and/or IO#trysendfile is unavailable def write_response(status, headers, body, alive) write_headers(status, headers, alive) write_body_each(body) @@ -77,7 +77,7 @@ module Rainbows::Response end include Each - if IO.method_defined?(:sendfile_nonblock) + if IO.method_defined?(:trysendfile) module Sendfile def write_body_file(body, range) io = body_to_io(body) @@ -90,7 +90,7 @@ module Rainbows::Response end if IO.respond_to?(:copy_stream) - unless IO.method_defined?(:sendfile_nonblock) + unless IO.method_defined?(:trysendfile) module CopyStream def write_body_file(body, range) range ? IO.copy_stream(body, self, range[1], range[0]) : @@ -111,7 +111,7 @@ module Rainbows::Response alias write_body_stream write_body_each end # ! IO.respond_to?(:copy_stream) - if IO.method_defined?(:sendfile_nonblock) || IO.respond_to?(:copy_stream) + if IO.method_defined?(:trysendfile) || IO.respond_to?(:copy_stream) HTTP_RANGE = 'HTTP_RANGE' Content_Range = 'Content-Range'.freeze @@ -181,5 +181,5 @@ module Rainbows::Response end end include ToPath - end # IO.respond_to?(:copy_stream) || IO.method_defined?(:sendfile_nonblock) + end # IO.respond_to?(:copy_stream) || IO.method_defined?(:trysendfile) end -- cgit v1.2.3-24-ge0c7