0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-16 05:00:24 +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:
Loïc Hoguin 2013-01-22 02:34:18 +01:00
parent 297ae32af1
commit 647e95aed1
27 changed files with 76 additions and 99 deletions

View file

@ -87,7 +87,7 @@ handlers, Websocket handlers, REST handlers and static handlers. Their
usage is documented in the respective sections of the guide.
Most applications use the plain HTTP handler, which has three callback
functions: init/3, handle/2 and terminate/2. Following is an example of
functions: init/3, handle/2 and terminate/3. Following is an example of
a simple handler module.
``` erlang
@ -96,7 +96,7 @@ a simple handler module.
-export([init/3]).
-export([handle/2]).
-export([terminate/2]).
-export([terminate/3]).
init({tcp, http}, Req, Opts) ->
{ok, Req, undefined_state}.
@ -105,7 +105,7 @@ handle(Req, State) ->
{ok, Req2} = cowboy_req:reply(200, [], <<"Hello World!">>, Req),
{ok, Req2, State}.
terminate(Req, State) ->
terminate(Reason, Req, State) ->
ok.
```