diff options
author | Loïc Hoguin <[email protected]> | 2025-04-10 15:15:09 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2025-04-10 15:15:09 +0200 |
commit | 9c9547971e8935a77a775d4e9208e0781dfda5f8 (patch) | |
tree | d3e2ce1ae38b43af57c2df00224f5b9120999503 /src | |
parent | d0ab49ed797e5bb48209825428d26947d74aabd5 (diff) | |
download | cowlib-9c9547971e8935a77a775d4e9208e0781dfda5f8.tar.gz cowlib-9c9547971e8935a77a775d4e9208e0781dfda5f8.tar.bz2 cowlib-9c9547971e8935a77a775d4e9208e0781dfda5f8.zip |
Add cow_http2_machine:terminate/1 for cleanup
This allows cleaning up timers and avoids receiving
stray timeout messages when reusing a process. This
is otherwise optional since the termination of a
process cleans up the timers.
Diffstat (limited to 'src')
-rw-r--r-- | src/cow_http2_machine.erl | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/cow_http2_machine.erl b/src/cow_http2_machine.erl index 4e57c04..794598a 100644 --- a/src/cow_http2_machine.erl +++ b/src/cow_http2_machine.erl @@ -15,6 +15,7 @@ -module(cow_http2_machine). -export([init/2]). +-export([terminate/1]). -export([init_stream/2]). -export([init_upgrade_stream/2]). -export([frame/2]). @@ -258,6 +259,17 @@ setting_from_opt(Settings, Opts, OptName, SettingName, Default) -> Value -> Settings#{SettingName => Value} end. +-spec terminate(State::http2_machine()) -> ok. +terminate(#http2_machine{preface_timer=PTRef, settings_timer=STRef}) -> + case PTRef of + undefined -> ok; + _ -> erlang:cancel_timer(PTRef, [{async, true}, {info, false}]) + end, + case STRef of + undefined -> ok; + _ -> erlang:cancel_timer(STRef, [{async, true}, {info, false}]) + end. + -spec init_stream(binary(), State) -> {ok, cow_http2:streamid(), State} when State::http2_machine(). init_stream(Method, State=#http2_machine{mode=client, local_streamid=LocalStreamID, @@ -996,11 +1008,11 @@ ignored_frame(State) -> timeout(preface_timeout, TRef, State=#http2_machine{preface_timer=TRef}) -> {error, {connection_error, protocol_error, 'The preface was not received in a reasonable amount of time.'}, - State}; + State#http2_machine{preface_timer=undefined}}; timeout(settings_timeout, TRef, State=#http2_machine{settings_timer=TRef}) -> {error, {connection_error, settings_timeout, 'The SETTINGS ack was not received within the configured time. (RFC7540 6.5.3)'}, - State}; + State#http2_machine{settings_timer=undefined}}; timeout(_, _, State) -> {ok, State}. |