aboutsummaryrefslogtreecommitdiffstats
path: root/src/gun.erl
diff options
context:
space:
mode:
authorViktor Söderqvist <[email protected]>2022-10-24 14:09:59 +0200
committerLoïc Hoguin <[email protected]>2022-10-24 14:44:15 +0200
commit1cc3b32b8ef6c187b8be3601319e21c1ba04fa27 (patch)
tree790f27c916f38858d9cca3e18a9f76a6f5ed163c /src/gun.erl
parenta4425a1d7db2d9e35f246aa078c324988ea395f0 (diff)
downloadgun-1cc3b32b8ef6c187b8be3601319e21c1ba04fa27.tar.gz
gun-1cc3b32b8ef6c187b8be3601319e21c1ba04fa27.tar.bz2
gun-1cc3b32b8ef6c187b8be3601319e21c1ba04fa27.zip
Handle send errors
Diffstat (limited to 'src/gun.erl')
-rw-r--r--src/gun.erl30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/gun.erl b/src/gun.erl
index bfb1bc4..4108b93 100644
--- a/src/gun.erl
+++ b/src/gun.erl
@@ -1237,17 +1237,25 @@ connected_ws_only(Type, Event, State) ->
connected(internal, {connected, Socket, NewProtocol},
State0=#state{owner=Owner, opts=Opts, transport=Transport}) ->
{Protocol, ProtoOpts} = gun_protocols:handler_and_opts(NewProtocol, Opts),
- %% @todo Handle error result from Protocol:init/4
- {ok, StateName, ProtoState} = Protocol:init(Owner, Socket, Transport, ProtoOpts),
- Owner ! {gun_up, self(), Protocol:name()},
- case active(State0#state{socket=Socket, protocol=Protocol, protocol_state=ProtoState}) of
- {ok, State} ->
- case Protocol:has_keepalive() of
- true -> {next_state, StateName, keepalive_timeout(State)};
- false -> {next_state, StateName, State}
- end;
- Disconnect ->
- Disconnect
+ case Protocol:init(Owner, Socket, Transport, ProtoOpts) of
+ Error={error, _} ->
+ %% @todo Don't send gun_up and gun_down if Protocol:init/4 failes here.
+ Owner ! {gun_up, self(), Protocol:name()},
+ disconnect(State0, Error);
+ {ok, StateName, ProtoState} ->
+ %% @todo Don't send gun_up and gun_down if active/1 failes here.
+ Owner ! {gun_up, self(), Protocol:name()},
+ State1 = State0#state{socket=Socket, protocol=Protocol, protocol_state=ProtoState},
+ case active(State1) of
+ {ok, State2} ->
+ State = case Protocol:has_keepalive() of
+ true -> keepalive_timeout(State2);
+ false -> State2
+ end,
+ {next_state, StateName, State};
+ Disconnect ->
+ Disconnect
+ end
end;
%% Public HTTP interface.
%%