diff options
Diffstat (limited to 'lib/rainbows/rev/sendfile.rb')
-rw-r--r-- | lib/rainbows/rev/sendfile.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/rainbows/rev/sendfile.rb b/lib/rainbows/rev/sendfile.rb index 9ab28bd..03ce41c 100644 --- a/lib/rainbows/rev/sendfile.rb +++ b/lib/rainbows/rev/sendfile.rb @@ -1,13 +1,28 @@ # -*- encoding: binary -*- module Rainbows::Rev::Sendfile if IO.method_defined?(:sendfile_nonblock) + class F < Struct.new(:offset, :to_io) + def close + to_io.close + self.to_io = nil + end + end + + def to_sendfile(io) + F[0, io] + end + def rev_sendfile(body) - body.pos += @_io.sendfile_nonblock(body, body.pos, 0x10000) + body.offset += @_io.sendfile_nonblock(body, body.offset, 0x10000) rescue Errno::EAGAIN ensure enable_write_watcher end else + def to_sendfile(io) + io + end + def rev_sendfile(body) write(body.sysread(0x4000)) end |