mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-15 12:40:25 +00:00
Replace terminate/2 with terminate/3, adding a Reason
This should have been done a *long* time ago, back when I initially added Websocket support. This is the first part of two in improving loop handler support with regards to socket closure. Reason may include: {normal, shutdown} for the most normal shutdown, {normal, timeout} for a loop handler timeout shutdown, or {error, _} if an error occured.
This commit is contained in:
parent
297ae32af1
commit
647e95aed1
27 changed files with 76 additions and 99 deletions
|
@ -23,8 +23,8 @@
|
|||
%% receive. It receives the message and the state previously defined.
|
||||
%% It can decide to stop the receive loop or continue receiving.
|
||||
%%
|
||||
%% <em>terminate/2</em> allows you to clean up. It receives the state
|
||||
%% previously defined.
|
||||
%% <em>terminate/3</em> allows you to clean up. It receives the
|
||||
%% termination reason and the state previously defined.
|
||||
%%
|
||||
%% There is no required operation to perform in any of these callbacks
|
||||
%% other than returning the proper values. Make sure you always return
|
||||
|
@ -39,6 +39,9 @@
|
|||
|
||||
-type opts() :: any().
|
||||
-type state() :: any().
|
||||
-type terminate_reason() :: {normal, shutdown}
|
||||
| {normal, timeout}
|
||||
| {error, atom()}.
|
||||
|
||||
-callback init({atom(), http}, Req, opts())
|
||||
-> {ok, Req, state()}
|
||||
|
@ -54,4 +57,4 @@
|
|||
| {loop, Req, State}
|
||||
| {loop, Req, State, hibernate}
|
||||
when Req::cowboy_req:req(), State::state().
|
||||
-callback terminate(cowboy_req:req(), state()) -> ok.
|
||||
-callback terminate(terminate_reason(), cowboy_req:req(), state()) -> ok.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue