Skip to content

Commit ef583af

Browse files
committed
Rename window_size field to send_window_size
The connection and stream structs tracked a `window_size` field for the client's outbound (send) window and a separately-named `receive_window_size` field for the inbound window. Renaming the former to `send_window_size` makes the pair symmetric and removes a long-standing source of confusion about which direction a bare `window_size` refers to.
1 parent 530f3ec commit ef583af

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

lib/mint/http2.ex

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ defmodule Mint.HTTP2 do
176176

177177
# Fields of the connection.
178178
buffer: "",
179-
# `window_size` is the client *send* window for the connection — how
180-
# much request-body data we're allowed to send to the server before it
181-
# refills the window with a WINDOW_UPDATE frame.
182-
window_size: @default_window_size,
179+
# `send_window_size` is the client *send* window for the connection
180+
# — how much request-body data we're allowed to send to the server
181+
# before it refills the window with a WINDOW_UPDATE frame.
182+
send_window_size: @default_window_size,
183183
# `receive_window_size` is the client *receive* window for the
184184
# connection — the peak size we've advertised to the server via
185185
# `WINDOW_UPDATE` frames on stream 0 (or the spec default of 65_535
@@ -804,13 +804,13 @@ defmodule Mint.HTTP2 do
804804
def get_window_size(conn, connection_or_request)
805805

806806
def get_window_size(%__MODULE__{} = conn, :connection) do
807-
conn.window_size
807+
conn.send_window_size
808808
end
809809

810810
def get_window_size(%__MODULE__{} = conn, {:request, request_ref}) do
811811
case Map.fetch(conn.ref_to_stream_id, request_ref) do
812812
{:ok, stream_id} ->
813-
conn.streams[stream_id].window_size
813+
conn.streams[stream_id].send_window_size
814814

815815
:error ->
816816
raise ArgumentError,
@@ -1219,7 +1219,7 @@ defmodule Mint.HTTP2 do
12191219
# Client send window — decremented as we send body bytes, refilled
12201220
# by incoming WINDOW_UPDATE frames from the server. Bounded initially
12211221
# by the server's SETTINGS_INITIAL_WINDOW_SIZE.
1222-
window_size: conn.server_settings.initial_window_size,
1222+
send_window_size: conn.server_settings.initial_window_size,
12231223
# Client receive window — the peak we've advertised to the server
12241224
# for this stream. Starts at whatever we told the server via our
12251225
# SETTINGS_INITIAL_WINDOW_SIZE; can be bumped per-stream with
@@ -1354,11 +1354,11 @@ defmodule Mint.HTTP2 do
13541354
data_size = IO.iodata_length(data)
13551355

13561356
cond do
1357-
data_size > stream.window_size ->
1358-
throw({:mint, conn, wrap_error({:exceeds_window_size, :request, stream.window_size})})
1357+
data_size > stream.send_window_size ->
1358+
throw({:mint, conn, wrap_error({:exceeds_window_size, :request, stream.send_window_size})})
13591359

1360-
data_size > conn.window_size ->
1361-
throw({:mint, conn, wrap_error({:exceeds_window_size, :connection, conn.window_size})})
1360+
data_size > conn.send_window_size ->
1361+
throw({:mint, conn, wrap_error({:exceeds_window_size, :connection, conn.send_window_size})})
13621362

13631363
# If the data size is greater than the max frame size, we chunk automatically based
13641364
# on the max frame size.
@@ -1386,8 +1386,8 @@ defmodule Mint.HTTP2 do
13861386
when is_integer(stream_id) and is_list(enabled_flags) do
13871387
chunk_size = IO.iodata_length(chunk)
13881388
frame = data(stream_id: stream_id, flags: set_flags(:data, enabled_flags), data: chunk)
1389-
conn = update_in(conn.streams[stream_id].window_size, &(&1 - chunk_size))
1390-
conn = update_in(conn.window_size, &(&1 - chunk_size))
1389+
conn = update_in(conn.streams[stream_id].send_window_size, &(&1 - chunk_size))
1390+
conn = update_in(conn.send_window_size, &(&1 - chunk_size))
13911391

13921392
conn =
13931393
if :end_stream in enabled_flags do
@@ -2005,16 +2005,16 @@ defmodule Mint.HTTP2 do
20052005
for {stream_id, stream} <- streams,
20062006
stream.state in [:open, :half_closed_remote],
20072007
into: streams do
2008-
window_size = stream.window_size + diff
2008+
send_window_size = stream.send_window_size + diff
20092009

2010-
if window_size > @max_window_size do
2010+
if send_window_size > @max_window_size do
20112011
debug_data =
2012-
"INITIAL_WINDOW_SIZE parameter of #{window_size} makes some window sizes too big"
2012+
"INITIAL_WINDOW_SIZE parameter of #{send_window_size} makes some window sizes too big"
20132013

20142014
send_connection_error!(conn, :flow_control_error, debug_data)
20152015
end
20162016

2017-
{stream_id, %{stream | window_size: window_size}}
2017+
{stream_id, %{stream | send_window_size: send_window_size}}
20182018
end
20192019
end)
20202020

@@ -2073,7 +2073,7 @@ defmodule Mint.HTTP2 do
20732073
id: promised_stream_id,
20742074
ref: make_ref(),
20752075
state: :reserved_remote,
2076-
window_size: conn.server_settings.initial_window_size,
2076+
send_window_size: conn.server_settings.initial_window_size,
20772077
received_first_headers?: false
20782078
}
20792079

@@ -2170,12 +2170,12 @@ defmodule Mint.HTTP2 do
21702170
window_update(stream_id: 0, window_size_increment: wsi),
21712171
responses
21722172
) do
2173-
new_window_size = conn.window_size + wsi
2173+
new_window_size = conn.send_window_size + wsi
21742174

21752175
if new_window_size > @max_window_size do
21762176
send_connection_error!(conn, :flow_control_error, "window size too big")
21772177
else
2178-
conn = put_in(conn.window_size, new_window_size)
2178+
conn = put_in(conn.send_window_size, new_window_size)
21792179
{conn, responses}
21802180
end
21812181
end
@@ -2186,14 +2186,14 @@ defmodule Mint.HTTP2 do
21862186
responses
21872187
) do
21882188
stream = fetch_stream!(conn, stream_id)
2189-
new_window_size = conn.streams[stream_id].window_size + wsi
2189+
new_window_size = conn.streams[stream_id].send_window_size + wsi
21902190

21912191
if new_window_size > @max_window_size do
21922192
conn = close_stream!(conn, stream_id, :flow_control_error)
21932193
error = wrap_error({:flow_control_error, "window size too big"})
21942194
{conn, [{:error, stream.ref, error} | responses]}
21952195
else
2196-
conn = put_in(conn.streams[stream_id].window_size, new_window_size)
2196+
conn = put_in(conn.streams[stream_id].send_window_size, new_window_size)
21972197
{conn, responses}
21982198
end
21992199
end

0 commit comments

Comments
 (0)