aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-10-10 11:33:35 +0200
committerLoïc Hoguin <[email protected]>2019-10-10 11:33:35 +0200
commitd52e84bdd97b93d7d9cea827de57bd4a0edea9a8 (patch)
tree48958da1fc3bd2b2e3666fc9ee2b545099116d47 /src
parentcc54c207e35f3ab7a2dfc105eef39fe7d3bf1633 (diff)
downloadcowboy-d52e84bdd97b93d7d9cea827de57bd4a0edea9a8.tar.gz
cowboy-d52e84bdd97b93d7d9cea827de57bd4a0edea9a8.tar.bz2
cowboy-d52e84bdd97b93d7d9cea827de57bd4a0edea9a8.zip
Add shutdown_reason Websocket command
This allows changing the normal exit reason of Websocket processes, providing a way to signal other processes of why the exit occurred.
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_websocket.erl13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/cowboy_websocket.erl b/src/cowboy_websocket.erl
index ad0dad5..31103ac 100644
--- a/src/cowboy_websocket.erl
+++ b/src/cowboy_websocket.erl
@@ -35,6 +35,7 @@
| {active, boolean()}
| {deflate, boolean()}
| {set_options, map()}
+ | {shutdown_reason, any()}
].
-export_type([commands/0]).
@@ -95,7 +96,8 @@
utf8_state :: cow_ws:utf8_state(),
deflate = true :: boolean(),
extensions = #{} :: map(),
- req = #{} :: map()
+ req = #{} :: map(),
+ shutdown_reason = normal :: any()
}).
%% Because the HTTP/1.1 and HTTP/2 handshakes are so different,
@@ -546,6 +548,8 @@ commands([{set_options, SetOpts}|Tail], State0=#state{opts=Opts}, Data) ->
State0
end,
commands(Tail, State, Data);
+commands([{shutdown_reason, ShutdownReason}|Tail], State, Data) ->
+ commands(Tail, State#state{shutdown_reason=ShutdownReason}, Data);
commands([Frame|Tail], State, Data0) ->
Data = [frame(Frame, State)|Data0],
case is_close_frame(Frame) of
@@ -623,9 +627,12 @@ frame(Frame, #state{extensions=Extensions}) ->
cow_ws:frame(Frame, Extensions).
-spec terminate(#state{}, any(), terminate_reason()) -> no_return().
-terminate(State, HandlerState, Reason) ->
+terminate(State=#state{shutdown_reason=Shutdown}, HandlerState, Reason) ->
handler_terminate(State, HandlerState, Reason),
- exit(normal).
+ case Shutdown of
+ normal -> exit(normal);
+ _ -> exit({shutdown, Shutdown})
+ end.
handler_terminate(#state{handler=Handler, req=Req}, HandlerState, Reason) ->
cowboy_handler:terminate(Reason, Req, HandlerState, Handler).