aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2014-11-07 19:22:36 +0200
committerLoïc Hoguin <[email protected]>2014-11-07 19:22:36 +0200
commit8cbd8c1882e33380875f2723cad258784ba3a360 (patch)
treee04ee8ab09bffcfe8c8bab25e509b626dc42be24
parent903f6f4c7d7aca0432e8f8ac3c1790e82b1428fd (diff)
downloadcowboy-8cbd8c1882e33380875f2723cad258784ba3a360.tar.gz
cowboy-8cbd8c1882e33380875f2723cad258784ba3a360.tar.bz2
cowboy-8cbd8c1882e33380875f2723cad258784ba3a360.zip
Rename 'shutdown' close reason and tuples to 'stop'
The 'shutdown' atom has a specific meaning inside OTP. We are instead going to use 'stop' which is pretty much the equivalent of what we actually do. 'shutdown' is now reserved for future special processes implementation.
-rw-r--r--doc/src/guide/loop_handlers.ezdoc6
-rw-r--r--doc/src/guide/ws_handlers.ezdoc6
-rw-r--r--doc/src/manual/cowboy_loop.ezdoc8
-rw-r--r--doc/src/manual/cowboy_websocket.ezdoc12
-rw-r--r--src/cowboy_loop.erl6
-rw-r--r--src/cowboy_websocket.erl41
-rw-r--r--test/handlers/long_polling_h.erl4
-rw-r--r--test/handlers/loop_handler_body_h.erl4
-rw-r--r--test/handlers/loop_handler_timeout_h.erl2
-rw-r--r--test/http_SUITE_data/http_loop_stream_recv.erl4
10 files changed, 46 insertions, 47 deletions
diff --git a/doc/src/guide/loop_handlers.ezdoc b/doc/src/guide/loop_handlers.ezdoc
index 2324cfd..879013b 100644
--- a/doc/src/guide/loop_handlers.ezdoc
+++ b/doc/src/guide/loop_handlers.ezdoc
@@ -61,7 +61,7 @@ message otherwise.
``` erlang
info({reply, Body}, Req, State) ->
Req2 = cowboy_req:reply(200, [], Body, Req),
- {shutdown, Req2, State};
+ {stop, Req2, State};
info(_Msg, Req, State) ->
{ok, Req, State, hibernate}.
```
@@ -76,7 +76,7 @@ return a tuple indicating if more messages are to be expected.
The callback may also choose to do nothing at all and just
skip the message received.
-If a reply is sent, then the `shutdown` tuple should be returned.
+If a reply is sent, then the `stop` tuple should be returned.
This will instruct Cowboy to end the request.
Otherwise an `ok` tuple should be returned.
@@ -99,7 +99,7 @@ init(Req, Opts) ->
{cowboy_loop, Req2, Opts}.
info(eof, Req, State) ->
- {shutdown, Req, State};
+ {stop, Req, State};
info({chunk, Chunk}, Req, State) ->
cowboy_req:chunk(Chunk, Req),
{ok, Req, State};
diff --git a/doc/src/guide/ws_handlers.ezdoc b/doc/src/guide/ws_handlers.ezdoc
index cb30511..811e021 100644
--- a/doc/src/guide/ws_handlers.ezdoc
+++ b/doc/src/guide/ws_handlers.ezdoc
@@ -42,7 +42,7 @@ init(Req, _Opts) ->
<<"mychat2">>, Req),
{ok, Req2, #state{}};
false ->
- {shutdown, Req, undefined}
+ {stop, Req, undefined}
end
end.
```
@@ -75,7 +75,7 @@ ping or pong frame arrives from the client. Note that in the
case of ping and pong frames, no action is expected as Cowboy
automatically replies to ping frames.
-The handler can decide to send frames to the socket, shutdown
+The handler can decide to send frames to the socket, stop
or just continue without sending anything.
The following snippet echoes back any text frame received and
@@ -93,7 +93,7 @@ websocket_handle(_Frame, Req, State) ->
Cowboy will call `websocket_info/3` whenever an Erlang message
arrives.
-The handler can decide to send frames to the socket, shutdown
+The handler can decide to send frames to the socket, stop
or just continue without sending anything.
The following snippet forwards any `log` message to the socket
diff --git a/doc/src/manual/cowboy_loop.ezdoc b/doc/src/manual/cowboy_loop.ezdoc
index 196cec6..79b96f9 100644
--- a/doc/src/manual/cowboy_loop.ezdoc
+++ b/doc/src/manual/cowboy_loop.ezdoc
@@ -29,10 +29,10 @@ The connection was closed normally before switching to the
loop sub protocol. This typically happens if an `ok` tuple is
returned from the `init/2` callback.
-: shutdown
+: stop
The handler requested to close the connection by returning
-a `shutdown` tuple.
+a `stop` tuple.
: timeout
@@ -72,7 +72,7 @@ A socket error ocurred.
: info(Info, Req, State)
-> {ok, Req, State}
| {ok, Req, State, hibernate}
- | {shutdown, Req, State}
+ | {stop, Req, State}
Types:
@@ -85,7 +85,7 @@ Handle the Erlang message received.
This function will be called every time an Erlang message
has been received. The message can be any Erlang term.
-The `shutdown` return value can be used to stop the receive loop,
+The `stop` return value can be used to stop the receive loop,
typically because a response has been sent.
The `hibernate` option will hibernate the process until
diff --git a/doc/src/manual/cowboy_websocket.ezdoc b/doc/src/manual/cowboy_websocket.ezdoc
index 7311662..8aac4cf 100644
--- a/doc/src/manual/cowboy_websocket.ezdoc
+++ b/doc/src/manual/cowboy_websocket.ezdoc
@@ -69,10 +69,10 @@ further details.
The remote endpoint closed the connection with the given
`Code` and `Payload` as the reason.
-: shutdown
+: stop
The handler requested to close the connection, either by returning
-a `shutdown` tuple or by sending a `close` frame.
+a `stop` tuple or by sending a `close` frame.
: timeout
@@ -111,7 +111,7 @@ A socket error ocurred.
| {ok, Req, State, hibernate}
| {reply, OutFrame | [OutFrame], Req, State}
| {reply, OutFrame | [OutFrame], Req, State, hibernate}
- | {shutdown, Req, State}
+ | {stop, Req, State}
Types:
@@ -125,7 +125,7 @@ Handle the data received from the Websocket connection.
This function will be called every time data is received
from the Websocket connection.
-The `shutdown` return value can be used to close the
+The `stop` return value can be used to close the
connection. A close reply will also result in the connection
being closed.
@@ -138,7 +138,7 @@ Erlang message.
| {ok, Req, State, hibernate}
| {reply, OutFrame | [OutFrame], Req, State}
| {reply, OutFrame | [OutFrame], Req, State, hibernate}
- | {shutdown, Req, State}
+ | {stop, Req, State}
Types:
@@ -152,7 +152,7 @@ Handle the Erlang message received.
This function will be called every time an Erlang message
has been received. The message can be any Erlang term.
-The `shutdown` return value can be used to close the
+The `stop` return value can be used to close the
connection. A close reply will also result in the connection
being closed.
diff --git a/src/cowboy_loop.erl b/src/cowboy_loop.erl
index b9eb8cd..8920299 100644
--- a/src/cowboy_loop.erl
+++ b/src/cowboy_loop.erl
@@ -36,7 +36,7 @@
-callback info(any(), Req, State)
-> {ok, Req, State}
| {ok, Req, State, hibernate}
- | {shutdown, Req, State}
+ | {stop, Req, State}
when Req::cowboy_req:req(), State::any().
%% @todo optional -callback terminate(terminate_reason(), cowboy_req:req(), state()) -> ok.
@@ -153,8 +153,8 @@ call(Req, State=#state{resp_sent=RespSent},
after_call(Req2, State, Handler, HandlerState2);
{ok, Req2, HandlerState2, hibernate} ->
after_call(Req2, State#state{hibernate=true}, Handler, HandlerState2);
- {shutdown, Req2, HandlerState2} ->
- after_loop(Req2, State, Handler, HandlerState2, shutdown)
+ {stop, Req2, HandlerState2} ->
+ after_loop(Req2, State, Handler, HandlerState2, stop)
catch Class:Reason ->
Stacktrace = erlang:get_stacktrace(),
if RespSent -> ok; true ->
diff --git a/src/cowboy_websocket.erl b/src/cowboy_websocket.erl
index cdd0365..36190a5 100644
--- a/src/cowboy_websocket.erl
+++ b/src/cowboy_websocket.erl
@@ -33,7 +33,7 @@
-type frag_state() :: undefined
| {nofin, opcode(), binary()} | {fin, opcode(), binary()}.
-type rsv() :: << _:3 >>.
--type terminate_reason() :: normal | shutdown | timeout
+-type terminate_reason() :: normal | stop | timeout
| remote | {remote, close_code(), binary()}
| {error, badencoding | badframe | closed | atom()}
| {crash, error | exit | throw, any()}.
@@ -49,14 +49,14 @@
| {ok, Req, State, hibernate}
| {reply, frame() | [frame()], Req, State}
| {reply, frame() | [frame()], Req, State, hibernate}
- | {shutdown, Req, State}
+ | {stop, Req, State}
when Req::cowboy_req:req(), State::any().
-callback websocket_info(any(), Req, State)
-> {ok, Req, State}
| {ok, Req, State, hibernate}
| {reply, frame() | [frame()], Req, State}
| {reply, frame() | [frame()], Req, State, hibernate}
- | {shutdown, Req, State}
+ | {stop, Req, State}
when Req::cowboy_req:req(), State::any().
%% @todo optional -callback terminate(terminate_reason(), cowboy_req:req(), state()) -> ok.
@@ -581,8 +581,8 @@ handler_call(State=#state{handler=Handler}, Req, HandlerState,
case websocket_send_many(Payload, State) of
{ok, State2} ->
NextState(State2, Req2, HandlerState2, RemainingData);
- {shutdown, State2} ->
- handler_terminate(State2, Req2, HandlerState2, shutdown);
+ {stop, State2} ->
+ handler_terminate(State2, Req2, HandlerState2, stop);
{{error, _} = Error, State2} ->
handler_terminate(State2, Req2, HandlerState2, Error)
end;
@@ -592,8 +592,8 @@ handler_call(State=#state{handler=Handler}, Req, HandlerState,
{ok, State2} ->
NextState(State2#state{hibernate=true},
Req2, HandlerState2, RemainingData);
- {shutdown, State2} ->
- handler_terminate(State2, Req2, HandlerState2, shutdown);
+ {stop, State2} ->
+ handler_terminate(State2, Req2, HandlerState2, stop);
{{error, _} = Error, State2} ->
handler_terminate(State2, Req2, HandlerState2, Error)
end;
@@ -601,8 +601,8 @@ handler_call(State=#state{handler=Handler}, Req, HandlerState,
case websocket_send(Payload, State) of
{ok, State2} ->
NextState(State2, Req2, HandlerState2, RemainingData);
- {shutdown, State2} ->
- handler_terminate(State2, Req2, HandlerState2, shutdown);
+ {stop, State2} ->
+ handler_terminate(State2, Req2, HandlerState2, stop);
{{error, _} = Error, State2} ->
handler_terminate(State2, Req2, HandlerState2, Error)
end;
@@ -611,13 +611,13 @@ handler_call(State=#state{handler=Handler}, Req, HandlerState,
{ok, State2} ->
NextState(State2#state{hibernate=true},
Req2, HandlerState2, RemainingData);
- {shutdown, State2} ->
- handler_terminate(State2, Req2, HandlerState2, shutdown);
+ {stop, State2} ->
+ handler_terminate(State2, Req2, HandlerState2, stop);
{{error, _} = Error, State2} ->
handler_terminate(State2, Req2, HandlerState2, Error)
end;
- {shutdown, Req2, HandlerState2} ->
- websocket_close(State, Req2, HandlerState2, shutdown)
+ {stop, Req2, HandlerState2} ->
+ websocket_close(State, Req2, HandlerState2, stop)
catch Class:Reason ->
_ = websocket_close(State, Req, HandlerState, {crash, Class, Reason}),
erlang:Class([
@@ -652,12 +652,11 @@ websocket_deflate_frame(_, Payload, State=#state{deflate_state = Deflate}) ->
{Deflated1, << 1:1, 0:2 >>, State}.
-spec websocket_send(frame(), #state{})
--> {ok, #state{}} | {shutdown, #state{}} | {{error, atom()}, #state{}}.
-websocket_send(Type, State=#state{socket=Socket, transport=Transport})
- when Type =:= close ->
+-> {ok, #state{}} | {stop, #state{}} | {{error, atom()}, #state{}}.
+websocket_send(Type = close, State=#state{socket=Socket, transport=Transport}) ->
Opcode = websocket_opcode(Type),
case Transport:send(Socket, << 1:1, 0:3, Opcode:4, 0:8 >>) of
- ok -> {shutdown, State};
+ ok -> {stop, State};
Error -> {Error, State}
end;
websocket_send(Type, State=#state{socket=Socket, transport=Transport})
@@ -675,7 +674,7 @@ websocket_send({Type = close, StatusCode, Payload}, State=#state{
BinLen = payload_length_to_binary(Len),
Transport:send(Socket,
[<< 1:1, 0:3, Opcode:4, 0:1, BinLen/bits, StatusCode:16 >>, Payload]),
- {shutdown, State};
+ {stop, State};
websocket_send({Type, Payload0}, State=#state{socket=Socket, transport=Transport}) ->
Opcode = websocket_opcode(Type),
{Payload, Rsv, State2} = websocket_deflate_frame(Opcode, iolist_to_binary(Payload0), State),
@@ -700,13 +699,13 @@ payload_length_to_binary(N) ->
end.
-spec websocket_send_many([frame()], #state{})
- -> {ok, #state{}} | {shutdown, #state{}} | {{error, atom()}, #state{}}.
+ -> {ok, #state{}} | {stop, #state{}} | {{error, atom()}, #state{}}.
websocket_send_many([], State) ->
{ok, State};
websocket_send_many([Frame|Tail], State) ->
case websocket_send(Frame, State) of
{ok, State2} -> websocket_send_many(Tail, State2);
- {shutdown, State2} -> {shutdown, State2};
+ {stop, State2} -> {stop, State2};
{Error, State2} -> {Error, State2}
end.
@@ -716,7 +715,7 @@ websocket_send_many([Frame|Tail], State) ->
websocket_close(State=#state{socket=Socket, transport=Transport},
Req, HandlerState, Reason) ->
case Reason of
- Normal when Normal =:= shutdown; Normal =:= timeout ->
+ Normal when Normal =:= stop; Normal =:= timeout ->
Transport:send(Socket, << 1:1, 0:3, 8:4, 0:1, 2:7, 1000:16 >>);
{error, badframe} ->
Transport:send(Socket, << 1:1, 0:3, 8:4, 0:1, 2:7, 1002:16 >>);
diff --git a/test/handlers/long_polling_h.erl b/test/handlers/long_polling_h.erl
index 20fe7ee..4f8e23f 100644
--- a/test/handlers/long_polling_h.erl
+++ b/test/handlers/long_polling_h.erl
@@ -14,12 +14,12 @@ init(Req, _) ->
{cowboy_loop, Req, 2, 5000, hibernate}.
info(timeout, Req, 0) ->
- {shutdown, cowboy_req:reply(102, Req), 0};
+ {stop, cowboy_req:reply(102, Req), 0};
info(timeout, Req, Count) ->
erlang:send_after(200, self(), timeout),
{ok, Req, Count - 1, hibernate}.
-terminate(shutdown, _, 0) ->
+terminate(stop, _, 0) ->
ok;
terminate({error, overflow}, _, _) ->
ok.
diff --git a/test/handlers/loop_handler_body_h.erl b/test/handlers/loop_handler_body_h.erl
index 096fb3d..0d4fd4d 100644
--- a/test/handlers/loop_handler_body_h.erl
+++ b/test/handlers/loop_handler_body_h.erl
@@ -16,7 +16,7 @@ init(Req, _) ->
info(timeout, Req, State) ->
{ok, Body, Req2} = cowboy_req:body(Req),
100000 = byte_size(Body),
- {shutdown, cowboy_req:reply(200, Req2), State}.
+ {stop, cowboy_req:reply(200, Req2), State}.
-terminate(shutdown, _, _) ->
+terminate(stop, _, _) ->
ok.
diff --git a/test/handlers/loop_handler_timeout_h.erl b/test/handlers/loop_handler_timeout_h.erl
index a1bfa51..6502a3a 100644
--- a/test/handlers/loop_handler_timeout_h.erl
+++ b/test/handlers/loop_handler_timeout_h.erl
@@ -15,7 +15,7 @@ init(Req, _) ->
{cowboy_loop, Req, undefined, 200, hibernate}.
info(timeout, Req, State) ->
- {shutdown, cowboy_req:reply(500, Req), State}.
+ {stop, cowboy_req:reply(500, Req), State}.
terminate(timeout, _, _) ->
ok.
diff --git a/test/http_SUITE_data/http_loop_stream_recv.erl b/test/http_SUITE_data/http_loop_stream_recv.erl
index 4cd39a2..c006b6d 100644
--- a/test/http_SUITE_data/http_loop_stream_recv.erl
+++ b/test/http_SUITE_data/http_loop_stream_recv.erl
@@ -17,7 +17,7 @@ info(stream, Req, undefined) ->
stream(Req, ID, Acc) ->
case cowboy_req:body(Req) of
{ok, <<>>, Req2} ->
- {shutdown, cowboy_req:reply(200, Req2), undefined};
+ {stop, cowboy_req:reply(200, Req2), undefined};
{_, Data, Req2} ->
parse_id(Req2, ID, << Acc/binary, Data/binary >>)
end.
@@ -30,5 +30,5 @@ parse_id(Req, ID, Data) ->
stream(Req, ID, Data)
end.
-terminate(shutdown, _, _) ->
+terminate(stop, _, _) ->
ok.