class HTTP_Spew::InputSpray
Use this to wrap and replace your input object for spraying to multiple servers.
Public Class Methods
new(env, nr, input = env["rack.input"])
click to toggle source
# File lib/http_spew/input_spray.rb, line 5 def initialize(env, nr, input = env["rack.input"]) @input = input @pipes = {}.compare_by_identity nr.times do r, w = HTTP_Spew::ChunkyPipe.new @pipes[r] = w end start_write_driver end
Public Instance Methods
readers()
click to toggle source
# File lib/http_spew/input_spray.rb, line 15 def readers @pipes.keys end
start_write_driver()
click to toggle source
TODO: splice(2) if @input is an IO
# File lib/http_spew/input_spray.rb, line 29 def start_write_driver Thread.new do begin buf = "" while @input.read(0x4000, buf) @pipes.delete_if { |rd, wr| write_fail?(rd, wr, buf) }.empty? and raise HTTP_Spew::NoWritersError, "all writers have died", [] end buf.clear rescue => e @pipes.each { |rd, _| rd.error = e } ensure @pipes.each { |_, wr| wr.close unless wr.closed? } end end end
write_fail?(rd, wr, buf)
click to toggle source
# File lib/http_spew/input_spray.rb, line 19 def write_fail?(rd, wr, buf) wr.write(buf) false rescue => e rd.error = e wr.close true end