Browse Source

Add cow_http2_machine:get_connection_local_buffer_size/1

The function can be used to restrict how big all the
buffers of a single connection can get.
Loïc Hoguin 5 years ago
parent
commit
0a1fb6cc31
1 changed files with 9 additions and 0 deletions
  1. 9 0
      src/cow_http2_machine.erl

+ 9 - 0
src/cow_http2_machine.erl

@@ -29,6 +29,7 @@
 -export([update_window/2]).
 -export([update_window/3]).
 -export([reset_stream/2]).
+-export([get_connection_local_buffer_size/1]).
 -export([get_local_setting/2]).
 -export([get_last_streamid/1]).
 -export([get_stream_local_buffer_size/2]).
@@ -1408,6 +1409,14 @@ reset_stream(StreamID, State=#http2_machine{streams=Streams0}) ->
 			{error, not_found}
 	end.
 
+%% Retrieve the buffer size for all streams.
+
+-spec get_connection_local_buffer_size(http2_machine()) -> non_neg_integer().
+get_connection_local_buffer_size(#http2_machine{streams=Streams}) ->
+	lists:foldl(fun(#stream{local_buffer_size=Size}, Acc) ->
+		Acc + Size
+	end, 0, Streams).
+
 %% Retrieve a setting value, or its default value if not set.
 
 -spec get_local_setting(atom(), http2_machine()) -> atom() | integer().