lib/rainbows/writer_thread_pool.rb in rainbows-0.95.1 vs lib/rainbows/writer_thread_pool.rb in rainbows-0.96.0

- old
+ new

@@ -44,36 +44,36 @@ def closed? false end end - module Response # :nodoc: - def write_body(qclient, body) - qclient.q << [ qclient.to_io, :body, body ] - end - end - @@nr = 0 @@q = nil + def async_write_body(qclient, body, range) + qclient.q << [ qclient.to_io, :body, body, range ] + end + def process_client(client) # :nodoc: @@nr += 1 - super(QueueSocket[client, @@q[@@nr %= @@q.size]]) + super(QueueSocket.new(client, @@q[@@nr %= @@q.size])) end - def worker_loop(worker) # :nodoc: - Rainbows::Response.setup(self.class) + def init_worker_process(worker) + super self.class.__send__(:alias_method, :sync_write_body, :write_body) - self.class.__send__(:include, Response) + WriterThreadPool.__send__(:alias_method, :write_body, :async_write_body) + end + def worker_loop(worker) # :nodoc: # we have multiple, single-thread queues since we don't want to # interleave writes from the same client qp = (1..worker_connections).map do |n| QueuePool.new(1) do |response| begin - io, arg1, arg2 = response + io, arg1, arg2, arg3 = response case arg1 - when :body then sync_write_body(io, arg2) + when :body then sync_write_body(io, arg2, arg3) when :close then io.close unless io.closed? else io.write(arg1) end rescue => err