Module: HTTP::Protocol::HTTP2::FlowControl

Included in:
Connection, Stream
Defined in:
lib/http/protocol/http2/flow_control.rb

Instance Method Summary collapse

Instance Method Details

#available_frame_sizeObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/http/protocol/http2/flow_control.rb', line 27

def available_frame_size
	maximum_frame_size = self.maximum_frame_size
	available_size = @remote_window.available
	
	if available_size < maximum_frame_size
		return available_size
	else
		return maximum_frame_size
	end
end

#consume_local_window(frame) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/http/protocol/http2/flow_control.rb', line 52

def consume_local_window(frame)
	amount = frame.length
	
	@local_window.consume(amount)
	
	if @local_window.limited?
		self.send_window_update(@local_window.used)
	end
end

#consume_remote_window(frame) ⇒ Object

Keep track of the amount of data sent, and fail if is too much.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/http/protocol/http2/flow_control.rb', line 39

def consume_remote_window(frame)
	amount = frame.length
	
	# Frames with zero length with the END_STREAM flag set (that is, an empty DATA frame) MAY be sent if there is no available space in either flow-control window.
	if amount.zero? and frame.end_stream?
		# It's okay, we can send. No need to consume, it's empty anyway.
	elsif amount >= 0 and amount <= @remote_window.available
		@remote_window.consume(amount)
	else
		raise FlowControlError, "Trying to send #{frame.length} bytes, exceeded window size: #{@remote_window.available} (#{@remote_window})"
	end
end

#receive_window_update(frame) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/http/protocol/http2/flow_control.rb', line 72

def receive_window_update(frame)
	was_full = @remote_window.full?
	
	# puts "expand remote_window=#{@remote_window} by #{frame.unpack}"
	@remote_window.expand(frame.unpack)
	
	self.window_updated if was_full
end

#send_window_update(window_increment) ⇒ Object

Notify the remote end that we are prepared to receive more data:



63
64
65
66
67
68
69
70
# File 'lib/http/protocol/http2/flow_control.rb', line 63

def send_window_update(window_increment)
	frame = WindowUpdateFrame.new(self.id)
	frame.pack window_increment
	
	write_frame(frame)
	
	@local_window.expand(window_increment)
end

#window_updatedObject



81
82
# File 'lib/http/protocol/http2/flow_control.rb', line 81

def window_updated
end