1 # -*- encoding: binary -*-
3 # used to wrap a BasicSocket to use with +q+ for all writes
4 # this is compatible with IO.select
5 class Rainbows::WriterThreadPool::Client < Struct.new(:to_io, :q)
6 include Rainbows::SocketProxy
7 include Rainbows::ProcessClient
10 def write_body_each(body)
11 q << [ to_io, :write_body_each, body ]
14 def write_response_close(status, headers, body, alive)
15 to_io.instance_variable_set(:@hp, @hp) # XXX ugh
16 Rainbows::SyncClose.new(body) { |sync_body|
17 q << [ to_io, :write_response, status, headers, sync_body, alive ]
21 if IO.respond_to?(:copy_stream) || IO.method_defined?(:trysendfile)
22 def write_response(status, headers, body, alive)
23 if body.respond_to?(:close)
24 write_response_close(status, headers, body, alive)
25 elsif body.respond_to?(:to_path)
26 write_response_path(status, headers, body, alive)
32 def write_body_file(body, range)
33 q << [ to_io, :write_body_file, body, range ]
36 def write_body_stream(body)
37 q << [ to_io, :write_body_stream, body ]
39 else # each-only body response
40 def write_response(status, headers, body, alive)
41 if body.respond_to?(:close)
42 write_response_close(status, headers, body, alive)
47 end # each-only body response
56 q << [ to_io, :close ]