From a3308b8e4771eff64011bc683c7bdd94b79ceff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 16 Apr 2020 15:18:53 +0200 Subject: Empty the commands queue when returning --- src/gun_http2.erl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/gun_http2.erl') diff --git a/src/gun_http2.erl b/src/gun_http2.erl index 9edabaa..fef1096 100644 --- a/src/gun_http2.erl +++ b/src/gun_http2.erl @@ -153,11 +153,17 @@ switch_transport(Transport, Socket, State) -> %% This function is called before returning from handle/4. handle_ret(CommandOrCommands, #http2_state{commands_queue=[]}) -> - CommandOrCommands; + empty_commands_queue(CommandOrCommands); handle_ret(Commands, #http2_state{commands_queue=Queue}) when is_list(Commands) -> - lists:reverse(Queue, Commands); + lists:reverse(Queue, empty_commands_queue(Commands)); handle_ret(Command, #http2_state{commands_queue=Queue}) -> - lists:reverse([Command|Queue]). + lists:reverse([empty_commands_queue(Command)|Queue]). + +empty_commands_queue([{state, State}|Tail]) -> [{state, State#http2_state{commands_queue=[]}}|Tail]; +empty_commands_queue([Command|Tail]) -> [Command|empty_commands_queue(Tail)]; +empty_commands_queue([]) -> []; +empty_commands_queue({state, State}) -> {state, State#http2_state{commands_queue=[]}}; +empty_commands_queue(Command) -> Command. handle(Data, State=#http2_state{buffer=Buffer}, EvHandler, EvHandlerState) -> parse(<< Buffer/binary, Data/binary >>, State#http2_state{buffer= <<>>}, -- cgit v1.2.3