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.1.0+ gem includes IO#trysendfile
9 if IO.method_defined?(:trysendfile)
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 ]
13 case n = sock.trysendfile(body, offset, count)
16 return if 0 == (count -= n)
23 close_if_private(body)
27 def self.included(klass)
28 klass.__send__ :alias_method, :write_body_stream, :write_body_each