File tree Expand file tree Collapse file tree 4 files changed +35
-15
lines changed Expand file tree Collapse file tree 4 files changed +35
-15
lines changed Original file line number Diff line number Diff line change @@ -55,8 +55,8 @@ def initialize(framer, local_stream_id)
55
55
@decoder = HPACK ::Context . new
56
56
@encoder = HPACK ::Context . new
57
57
58
- @local_window = Window . new ( @local_settings . initial_window_size )
59
- @remote_window = Window . new ( @remote_settings . initial_window_size )
58
+ @local_window = LocalWindow . new
59
+ @remote_window = Window . new
60
60
end
61
61
62
62
def id
@@ -183,13 +183,6 @@ def send_settings(changes)
183
183
frame . pack ( changes )
184
184
185
185
write_frame ( frame )
186
-
187
- # If the initial window size is set to something bigger than the default, we want to increase it.
188
- difference = @local_settings . pending . initial_window_size - @local_window . capacity
189
-
190
- if difference > 0
191
- send_window_update ( difference )
192
- end
193
186
end
194
187
195
188
# Transition the connection into the closed state.
@@ -235,6 +228,8 @@ def update_local_settings(changes)
235
228
@streams . each_value do |stream |
236
229
stream . local_window . capacity = capacity
237
230
end
231
+
232
+ @local_window . desired = capacity
238
233
end
239
234
240
235
def update_remote_settings ( changes )
Original file line number Diff line number Diff line change @@ -60,13 +60,14 @@ def update_local_window(frame)
60
60
end
61
61
62
62
def consume_local_window ( frame )
63
+ # For flow-control calculations, the 9-octet frame header is not counted.
63
64
amount = frame . length
64
65
@local_window . consume ( amount )
65
66
end
66
67
67
68
def request_window_update
68
69
if @local_window . limited?
69
- self . send_window_update ( @local_window . used )
70
+ self . send_window_update ( @local_window . wanted )
70
71
end
71
72
end
72
73
Original file line number Diff line number Diff line change @@ -33,10 +33,6 @@ def initialize(capacity = 0xFFFF)
33
33
@capacity = capacity
34
34
end
35
35
36
- def dup
37
- return self . class . new ( @capacity )
38
- end
39
-
40
36
# The window is completely full?
41
37
def full?
42
38
@available <= 0
@@ -73,6 +69,10 @@ def expand(amount)
73
69
end
74
70
end
75
71
72
+ def wanted
73
+ @used
74
+ end
75
+
76
76
def limited?
77
77
@available < ( @capacity / 2 )
78
78
end
@@ -82,6 +82,30 @@ def to_s
82
82
end
83
83
end
84
84
85
+ # This is a window which efficiently maintains a desired capacity.
86
+ class LocalWindow < Window
87
+ def initialize ( capacity = 0xFFFF , desired : nil )
88
+ super ( capacity )
89
+
90
+ @desired = desired
91
+ end
92
+
93
+ attr_accessor :desired
94
+
95
+ def wanted
96
+ if @desired
97
+ # We must send an update which allows at least @desired bytes to be sent.
98
+ ( @desired - @capacity ) + @used
99
+ else
100
+ @used
101
+ end
102
+ end
103
+
104
+ def limited?
105
+ @available < ( ( @desired || @capacity ) / 2 )
106
+ end
107
+ end
108
+
85
109
# The WINDOW_UPDATE frame is used to implement flow control.
86
110
#
87
111
# +-+-------------------------------------------------------------+
Original file line number Diff line number Diff line change 87
87
expect ( frame . unpack ) . to eq 120
88
88
end
89
89
90
- context '#receive_window_update' do
90
+ describe '#receive_window_update' do
91
91
it "should be invoked when window update is received" do
92
92
# Write 200 bytes of data (client -> server) which exhausts server local window
93
93
stream . send_data ( "*" * 200 )
You can’t perform that action at this time.
0 commit comments