Class: ESI::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/esi/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Response

Returns a new instance of Response.



12
13
14
15
16
17
18
19
# File 'lib/esi/response.rb', line 12

def initialize( output )
  @count = 0
  @back_buffer = []
  @output = output
  @last_out = 0
  @threads = []
  @active_buffer = reserve_buffer
end

Instance Attribute Details

#active_bufferObject (readonly)

Returns the value of attribute active_buffer.



9
10
11
# File 'lib/esi/response.rb', line 9

def active_buffer
  @active_buffer
end

#outputObject

Returns the value of attribute output.



10
11
12
# File 'lib/esi/response.rb', line 10

def output
  @output
end

Instance Method Details

#flushObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/esi/response.rb', line 54

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_bufferObject



25
26
27
28
29
30
# File 'lib/esi/response.rb', line 25

def partial_buffer
  @active_buffer.close_write
  temp = reserve_buffer
  @active_buffer = reserve_buffer
  temp
end

#reserve_bufferObject

return’s new buffer



33
34
35
36
37
# File 'lib/esi/response.rb', line 33

def reserve_buffer
  buffer = @back_buffer[@count] = StringIO.new
  @count += 1
  buffer
end

#sendObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/esi/response.rb', line 39

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



21
22
23
# File 'lib/esi/response.rb', line 21

def update_output(output)
  @output = output
end

#wait_thread(thread) ⇒ Object



50
51
52
# File 'lib/esi/response.rb', line 50

def wait_thread(thread)
  @threads << thread
end