From 70ad994ae8a854477e45c877cd0e9dda41389f86 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 5 Jul 2010 08:07:03 +0000 Subject: rev: properly enable post-fork sendfile() usage We need to load sendfile-using parts after the "sendfile" library is loaded. --- lib/rainbows/rev/client.rb | 13 ------------- lib/rainbows/rev/core.rb | 2 ++ lib/rainbows/rev/sendfile.rb | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 lib/rainbows/rev/sendfile.rb diff --git a/lib/rainbows/rev/client.rb b/lib/rainbows/rev/client.rb index ababe50..68b3847 100644 --- a/lib/rainbows/rev/client.rb +++ b/lib/rainbows/rev/client.rb @@ -117,19 +117,6 @@ module Rainbows end while true end - if IO.method_defined?(:sendfile_nonblock) - def rev_sendfile(body) - body.pos += @_io.sendfile_nonblock(body, body.pos, 0x10000) - rescue Errno::EAGAIN - ensure - enable_write_watcher - end - else - def rev_sendfile(body) - write(body.sysread(CHUNK_SIZE)) - end - end - def on_write_complete if body = @deferred_bodies[0] # no socket or pipes, body must be a regular file to continue here diff --git a/lib/rainbows/rev/core.rb b/lib/rainbows/rev/core.rb index 7457f12..2488cf2 100644 --- a/lib/rainbows/rev/core.rb +++ b/lib/rainbows/rev/core.rb @@ -23,6 +23,8 @@ module Rainbows # given a INT, QUIT, or TERM signal) def worker_loop(worker) Rainbows::HttpResponse.setup(Rainbows::Rev::Client) + require 'rainbows/rev/sendfile' + Rainbows::Rev::Client.__send__(:include, Rainbows::Rev::Sendfile) init_worker_process(worker) mod = self.class.const_get(@use) rloop = Server.const_set(:LOOP, ::Rev::Loop.default) diff --git a/lib/rainbows/rev/sendfile.rb b/lib/rainbows/rev/sendfile.rb new file mode 100644 index 0000000..9ab28bd --- /dev/null +++ b/lib/rainbows/rev/sendfile.rb @@ -0,0 +1,15 @@ +# -*- encoding: binary -*- +module Rainbows::Rev::Sendfile + if IO.method_defined?(:sendfile_nonblock) + def rev_sendfile(body) + body.pos += @_io.sendfile_nonblock(body, body.pos, 0x10000) + rescue Errno::EAGAIN + ensure + enable_write_watcher + end + else + def rev_sendfile(body) + write(body.sysread(0x4000)) + end + end +end -- cgit v1.2.3-24-ge0c7