diff options
author | Loïc Hoguin <[email protected]> | 2019-05-13 14:04:34 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2019-05-13 14:04:34 +0200 |
commit | a309f196d15d3045d2e70b2d7e23858f47adb7df (patch) | |
tree | 6af8caa19dbccd790b4eefed298a924f682e4322 /src | |
parent | 3aa7168404e62f9ea9e290380b93569eff4372a8 (diff) | |
download | gun-a309f196d15d3045d2e70b2d7e23858f47adb7df.tar.gz gun-a309f196d15d3045d2e70b2d7e23858f47adb7df.tar.bz2 gun-a309f196d15d3045d2e70b2d7e23858f47adb7df.zip |
Add the terminate event
Diffstat (limited to 'src')
-rw-r--r-- | src/gun.erl | 9 | ||||
-rw-r--r-- | src/gun_default_event_h.erl | 4 | ||||
-rw-r--r-- | src/gun_event.erl | 10 |
3 files changed, 22 insertions, 1 deletions
diff --git a/src/gun.erl b/src/gun.erl index 44dbdeb..0ad12cf 100644 --- a/src/gun.erl +++ b/src/gun.erl @@ -94,6 +94,7 @@ -export([init/1]). -export([not_connected/3]). -export([connected/3]). +-export([terminate/3]). -type req_headers() :: [{binary() | string() | atom(), iodata()}] | #{binary() | string() | atom() => iodata()}. @@ -1077,3 +1078,11 @@ owner_down(normal) -> stop; owner_down(shutdown) -> {stop, shutdown}; owner_down(Shutdown = {shutdown, _}) -> {stop, Shutdown}; owner_down(Reason) -> {stop, {shutdown, {owner_down, Reason}}}. + +terminate(Reason, StateName, #state{event_handler=EventHandler, + event_handler_state=EventHandlerState}) -> + TerminateEvent = #{ + state => StateName, + reason => Reason + }, + EventHandler:terminate(TerminateEvent, EventHandlerState). diff --git a/src/gun_default_event_h.erl b/src/gun_default_event_h.erl index f234dda..6d64ff7 100644 --- a/src/gun_default_event_h.erl +++ b/src/gun_default_event_h.erl @@ -19,6 +19,7 @@ -export([connect_start/2]). -export([connect_end/2]). -export([disconnect/2]). +-export([terminate/2]). init(_EventData, State) -> State. @@ -31,3 +32,6 @@ connect_end(_EventData, State) -> disconnect(_EventData, State) -> State. + +terminate(_EventData, State) -> + State. diff --git a/src/gun_event.erl b/src/gun_event.erl index bb541ed..3d83bea 100644 --- a/src/gun_event.erl +++ b/src/gun_event.erl @@ -51,6 +51,15 @@ -callback disconnect(disconnect_event(), State) -> State. +%% terminate. + +-type terminate_event() :: #{ + state := not_connected | connected, + reason := normal | shutdown | {shutdown, any()} | any() +}. + +-callback terminate(terminate_event(), State) -> State. + %% @todo domain_lookup_start %% @todo domain_lookup_end %% @todo tls_handshake_start @@ -58,7 +67,6 @@ %% @todo origin_changed %% @todo transport_changed %% @todo protocol_changed -%% @todo terminate %% @todo stream_start %% @todo stream_end %% @todo request_start |