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 return if @hp.hijacked?
12 q << [ to_io, :write_body_each, body ]
15 def write_response_close(status, headers, body, alive)
16 to_io.instance_variable_set(:@hp, @hp) # XXX ugh
17 return if @hp.hijacked?
18 Rainbows::SyncClose.new(body) { |sync_body|
19 q << [ to_io, :write_response, status, headers, sync_body, alive ]
23 if Rainbows::Response::COPY_STREAM || IO.method_defined?(:trysendfile)
24 def write_response(status, headers, body, alive)
25 if body.respond_to?(:close)
26 write_response_close(status, headers, body, alive)
27 elsif body.respond_to?(:to_path)
28 write_response_path(status, headers, body, alive)
34 def write_body_file(body, range)
35 q << [ to_io, :write_body_file, body, range ]
38 def write_body_stream(body)
39 q << [ to_io, :write_body_stream, body ]
41 else # each-only body response
42 def write_response(status, headers, body, alive)
43 if body.respond_to?(:close)
44 write_response_close(status, headers, body, alive)
49 end # each-only body response
58 q << [ to_io, :close ]