From 1b7b5ca356609574dac30dbec846dbd75718624e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 10 Feb 2020 09:48:14 +0100 Subject: Handle cow_http2_machine timeouts --- src/gun.erl | 4 ++++ src/gun_http2.erl | 9 +++++++++ 2 files changed, 13 insertions(+) (limited to 'src') diff --git a/src/gun.erl b/src/gun.erl index 507eef7..b08057f 100644 --- a/src/gun.erl +++ b/src/gun.erl @@ -1224,6 +1224,10 @@ handle_common_connected(cast, {data, ReplyTo, StreamRef, IsFin, Data}, _, {ProtoState2, EvHandlerState} = Protocol:data(ProtoState, StreamRef, ReplyTo, IsFin, Data, EvHandler, EvHandlerState0), {keep_state, State#state{protocol_state=ProtoState2, event_handler_state=EvHandlerState}}; +handle_common_connected(info, {timeout, TRef, Name}, _, + State=#state{protocol=Protocol, protocol_state=ProtoState}) -> + Commands = Protocol:timeout(ProtoState, Name, TRef), + commands(Commands, State); handle_common_connected(Type, Event, StateName, StateData) -> handle_common_connected_no_input(Type, Event, StateName, StateData). diff --git a/src/gun_http2.erl b/src/gun_http2.erl index 8746b3e..b0397f0 100644 --- a/src/gun_http2.erl +++ b/src/gun_http2.erl @@ -30,6 +30,7 @@ -export([request/12]). -export([data/7]). -export([cancel/5]). +-export([timeout/3]). -export([stream_info/2]). -export([down/1]). @@ -709,6 +710,14 @@ cancel(State=#http2_state{socket=Socket, transport=Transport, http2_machine=HTTP EvHandlerState0} end. +timeout(State=#http2_state{http2_machine=HTTP2Machine0}, {cow_http2_machine, Name}, TRef) -> + case cow_http2_machine:timeout(Name, TRef, HTTP2Machine0) of + {ok, HTTP2Machine} -> + {state, State#http2_state{http2_machine=HTTP2Machine}}; + {error, Error={connection_error, _, _}, _HTTP2Machine} -> + connection_error(State, Error) + end. + stream_info(State, StreamRef) -> case get_stream_by_ref(State, StreamRef) of #stream{reply_to=ReplyTo} -> -- cgit v1.2.3