Browse Source

Add cow_http2_machine:get_stream_local_buffer_size/2

Loïc Hoguin 5 years ago
parent
commit
1d2904588c
1 changed files with 17 additions and 0 deletions
  1. 17 0
      src/cow_http2_machine.erl

+ 17 - 0
src/cow_http2_machine.erl

@@ -31,6 +31,7 @@
 -export([reset_stream/2]).
 -export([reset_stream/2]).
 -export([get_local_setting/2]).
 -export([get_local_setting/2]).
 -export([get_last_streamid/1]).
 -export([get_last_streamid/1]).
+-export([get_stream_local_buffer_size/2]).
 -export([get_stream_local_state/2]).
 -export([get_stream_local_state/2]).
 -export([get_stream_remote_state/2]).
 -export([get_stream_remote_state/2]).
 
 
@@ -1435,6 +1436,22 @@ default_setting_value(enable_connect_protocol) -> false.
 get_last_streamid(#http2_machine{remote_streamid=RemoteStreamID}) ->
 get_last_streamid(#http2_machine{remote_streamid=RemoteStreamID}) ->
 	RemoteStreamID.
 	RemoteStreamID.
 
 
+%% Retrieve the local buffer size for a stream.
+
+-spec get_stream_local_buffer_size(cow_http2:streamid(), http2_machine())
+	-> {ok, non_neg_integer()} | {error, not_found | closed}.
+get_stream_local_buffer_size(StreamID, State=#http2_machine{mode=Mode,
+		local_streamid=LocalStreamID, remote_streamid=RemoteStreamID}) ->
+	case stream_get(StreamID, State) of
+		#stream{local_buffer_size=Size} ->
+			{ok, Size};
+		undefined when (?IS_LOCAL(Mode, StreamID) andalso (StreamID < LocalStreamID))
+				orelse ((not ?IS_LOCAL(Mode, StreamID)) andalso (StreamID =< RemoteStreamID)) ->
+			{error, closed};
+		undefined ->
+			{error, not_found}
+	end.
+
 %% Retrieve the local state for a stream, including the state in the queue.
 %% Retrieve the local state for a stream, including the state in the queue.
 
 
 -spec get_stream_local_state(cow_http2:streamid(), http2_machine())
 -spec get_stream_local_state(cow_http2:streamid(), http2_machine())