rev/deferred_response: cleanups
[rainbows.git] / lib / rainbows / rev / sendfile.rb
blob414cfa1f0209647584d6bd70ad6f6383da0d3bad
1 # -*- encoding: binary -*-
2 # :enddoc:
3 module Rainbows::Rev::Sendfile
4   if IO.method_defined?(:sendfile_nonblock)
5     F = Rainbows::StreamFile
7     def to_sendfile(io)
8       F[0, io]
9     end
11     def rev_sendfile(body)
12       body.offset += @_io.sendfile_nonblock(body, body.offset, 0x10000)
13       enable_write_watcher
14       rescue Errno::EAGAIN
15         enable_write_watcher
16     end
17   else
18     def to_sendfile(io)
19       io
20     end
22     def rev_sendfile(body)
23       write(body.sysread(0x4000))
24     end
25   end
26 end