aboutsummaryrefslogtreecommitdiffstats
path: root/src/gun.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-01-05 11:53:31 +0100
committerLoïc Hoguin <[email protected]>2019-01-05 11:53:31 +0100
commit4bd87ba7d1699fc1b2901cd61b703429f1deff63 (patch)
treea24fe6638cbabc1a675f8f4df0ccd70ab5c0cbff /src/gun.erl
parentc2ba3ff0999f523b665dc0dbf100ed634bd1d6af (diff)
downloadgun-4bd87ba7d1699fc1b2901cd61b703429f1deff63.tar.gz
gun-4bd87ba7d1699fc1b2901cd61b703429f1deff63.tar.bz2
gun-4bd87ba7d1699fc1b2901cd61b703429f1deff63.zip
Ensure Gun retries connecting immediately
Diffstat (limited to 'src/gun.erl')
-rw-r--r--src/gun.erl20
1 files changed, 12 insertions, 8 deletions
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