From 4bd87ba7d1699fc1b2901cd61b703429f1deff63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sat, 5 Jan 2019 11:53:31 +0100 Subject: Ensure Gun retries connecting immediately --- src/gun.erl | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/gun.erl') diff --git a/src/gun.erl b/src/gun.erl index 09c0b95..a8b76f8 100644 --- a/src/gun.erl +++ b/src/gun.erl @@ -179,8 +179,7 @@ transport :: module(), messages :: {atom(), atom(), atom()}, protocol :: module(), - protocol_state :: any(), - last_error :: any() + protocol_state :: any() }). %% Connection. @@ -703,9 +702,9 @@ not_connected(_, {retries, Retries}, {next_event, internal, {connected, Socket, Protocol}}}; {error, Reason} when Retries =:= 0 -> {stop, {shutdown, Reason}}; - {error, Reason} -> + {error, _Reason} -> Timeout = maps:get(retry_timeout, Opts, 5000), - {keep_state, State#state{last_error=Reason}, + {keep_state, State, {state_timeout, Timeout, {retries, Retries - 1}}} end; not_connected(Type, Event, State) -> @@ -912,10 +911,15 @@ disconnect(State=#state{owner=Owner, opts=Opts, {KilledStreams, UnprocessedStreams} = Protocol:down(ProtoState), Owner ! {gun_down, self(), Protocol:name(), Reason, KilledStreams, UnprocessedStreams}, Retry = maps:get(retry, Opts, 5), - {next_state, not_connected, - keepalive_cancel(State#state{socket=undefined, - protocol=undefined, protocol_state=undefined, last_error=Reason}), - {next_event, internal, {retries, Retry}}}. + case Retry of + 0 -> + {stop, {shutdown, Reason}}; + _ -> + {next_state, not_connected, + keepalive_cancel(State#state{socket=undefined, + protocol=undefined, protocol_state=undefined}), + {next_event, internal, {retries, Retry - 1}}} + end. disconnect_flush(State=#state{socket=Socket, messages={OK, Closed, Error}}) -> receive -- cgit v1.2.3