Class: ESI::Response
- Inherits:
-
Object
- Object
- ESI::Response
- Defined in:
- lib/esi/response.rb
Instance Attribute Summary collapse
-
#active_buffer ⇒ Object
readonly
Returns the value of attribute active_buffer.
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
- #flush ⇒ Object
-
#initialize(output) ⇒ Response
constructor
A new instance of Response.
- #partial_buffer ⇒ Object
-
#reserve_buffer ⇒ Object
return’s new buffer.
- #send ⇒ Object
- #update_output(output) ⇒ Object
- #wait_thread(thread) ⇒ Object
Constructor Details
#initialize(output) ⇒ Response
Returns a new instance of Response.
41 42 43 44 45 46 47 48 |
# File 'lib/esi/response.rb', line 41 def initialize( output ) @count = 0 @back_buffer = [] @output = OutputAdapter.new(output) @last_out = 0 @threads = [] @active_buffer = reserve_buffer end |
Instance Attribute Details
#active_buffer ⇒ Object (readonly)
Returns the value of attribute active_buffer.
38 39 40 |
# File 'lib/esi/response.rb', line 38 def active_buffer @active_buffer end |
#output ⇒ Object
Returns the value of attribute output.
39 40 41 |
# File 'lib/esi/response.rb', line 39 def output @output end |
Instance Method Details
#flush ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/esi/response.rb', line 83 def flush @threads.each{|t| t.join } @active_buffer.close_write if !@active_buffer.closed_write? # roll up requests @last_out = 0 if @last_out == -1 tail_buffer = (@back_buffer[@last_out..@back_buffer.size]||[]) #puts "\nflushing: #{tail_buffer.inspect} from #{@back_buffer.inspect}" while !tail_buffer.empty? o = tail_buffer.shift unless o.nil? o.rewind buf = o.read #puts "flush : #{buf.inspect}" @output << buf end #puts "#{self} sending: #{@count-tail_buffer.size}" end end |
#partial_buffer ⇒ Object
54 55 56 57 58 59 |
# File 'lib/esi/response.rb', line 54 def partial_buffer @active_buffer.close_write temp = reserve_buffer @active_buffer = reserve_buffer temp end |
#reserve_buffer ⇒ Object
return’s new buffer
62 63 64 65 66 |
# File 'lib/esi/response.rb', line 62 def reserve_buffer buffer = @back_buffer[@count] = StringIO.new @count += 1 buffer end |
#send ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/esi/response.rb', line 68 def send check_buffers = @back_buffer[@last_out..@count] for buffer in check_buffers do break if buffer.nil? or !buffer.closed_write? buffer.rewind @output << buffer.read @last_out += 1 end end |
#update_output(output) ⇒ Object
50 51 52 |
# File 'lib/esi/response.rb', line 50 def update_output(output) @output = output end |
#wait_thread(thread) ⇒ Object
79 80 81 |
# File 'lib/esi/response.rb', line 79 def wait_thread(thread) @threads << thread end |