1 # -*- encoding: binary -*-
3 # non-portable body handling for Fiber-based concurrency goes here
4 # this module is required and included in worker processes only
5 # this is meant to be included _after_ Rainbows::Response::Body
6 module Rainbows::Fiber::Body # :nodoc:
8 # the sendfile 1.0.0+ gem includes IO#sendfile_nonblock
9 if IO.method_defined?(:sendfile_nonblock)
10 def write_body_file(body, range)
11 sock, n, body = to_io, nil, body_to_io(body)
12 offset, count = range ? range : [ 0, body.stat.size ]
14 offset += (n = sock.sendfile_nonblock(body, offset, count))
20 end while (count -= n) > 0
22 close_if_private(body)
26 def self.included(klass)
27 klass.__send__ :alias_method, :write_body_stream, :write_body_each