Browse Source

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.
Loïc Hoguin 10 years ago
parent
commit
8cbd8c1882

+ 3 - 3
doc/src/guide/loop_handlers.ezdoc

@@ -61,7 +61,7 @@ message otherwise.
 ``` erlang
 ``` erlang
 info({reply, Body}, Req, State) ->
 info({reply, Body}, Req, State) ->
     Req2 = cowboy_req:reply(200, [], Body, Req),
     Req2 = cowboy_req:reply(200, [], Body, Req),
-    {shutdown, Req2, State};
+    {stop, Req2, State};
 info(_Msg, Req, State) ->
 info(_Msg, Req, State) ->
     {ok, Req, State, hibernate}.
     {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
 The callback may also choose to do nothing at all and just
 skip the message received.
 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.
 This will instruct Cowboy to end the request.
 
 
 Otherwise an `ok` tuple should be returned.
 Otherwise an `ok` tuple should be returned.
@@ -99,7 +99,7 @@ init(Req, Opts) ->
     {cowboy_loop, Req2, Opts}.
     {cowboy_loop, Req2, Opts}.
 
 
 info(eof, Req, State) ->
 info(eof, Req, State) ->
-    {shutdown, Req, State};
+    {stop, Req, State};
 info({chunk, Chunk}, Req, State) ->
 info({chunk, Chunk}, Req, State) ->
     cowboy_req:chunk(Chunk, Req),
     cowboy_req:chunk(Chunk, Req),
     {ok, Req, State};
     {ok, Req, State};

+ 3 - 3
doc/src/guide/ws_handlers.ezdoc

@@ -42,7 +42,7 @@ init(Req, _Opts) ->
 						<<"mychat2">>, Req),
 						<<"mychat2">>, Req),
 					{ok, Req2, #state{}};
 					{ok, Req2, #state{}};
 				false ->
 				false ->
-					{shutdown, Req, undefined}
+					{stop, Req, undefined}
 			end
 			end
 	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
 case of ping and pong frames, no action is expected as Cowboy
 automatically replies to ping frames.
 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.
 or just continue without sending anything.
 
 
 The following snippet echoes back any text frame received and
 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
 Cowboy will call `websocket_info/3` whenever an Erlang message
 arrives.
 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.
 or just continue without sending anything.
 
 
 The following snippet forwards any `log` message to the socket
 The following snippet forwards any `log` message to the socket

+ 4 - 4
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
 loop sub protocol. This typically happens if an `ok` tuple is
 returned from the `init/2` callback.
 returned from the `init/2` callback.
 
 
-: shutdown
+: stop
 
 
 The handler requested to close the connection by returning
 The handler requested to close the connection by returning
-a `shutdown` tuple.
+a `stop` tuple.
 
 
 : timeout
 : timeout
 
 
@@ -72,7 +72,7 @@ A socket error ocurred.
 : info(Info, Req, State)
 : info(Info, Req, State)
 	-> {ok, Req, State}
 	-> {ok, Req, State}
 	| {ok, Req, State, hibernate}
 	| {ok, Req, State, hibernate}
-	| {shutdown, Req, State}
+	| {stop, Req, State}
 
 
 Types:
 Types:
 
 
@@ -85,7 +85,7 @@ Handle the Erlang message received.
 This function will be called every time an Erlang message
 This function will be called every time an Erlang message
 has been received. The message can be any Erlang term.
 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.
 typically because a response has been sent.
 
 
 The `hibernate` option will hibernate the process until
 The `hibernate` option will hibernate the process until

+ 6 - 6
doc/src/manual/cowboy_websocket.ezdoc

@@ -69,10 +69,10 @@ further details.
 The remote endpoint closed the connection with the given
 The remote endpoint closed the connection with the given
 `Code` and `Payload` as the reason.
 `Code` and `Payload` as the reason.
 
 
-: shutdown
+: stop
 
 
 The handler requested to close the connection, either by returning
 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
 : timeout
 
 
@@ -111,7 +111,7 @@ A socket error ocurred.
 	| {ok, Req, State, hibernate}
 	| {ok, Req, State, hibernate}
 	| {reply, OutFrame | [OutFrame], Req, State}
 	| {reply, OutFrame | [OutFrame], Req, State}
 	| {reply, OutFrame | [OutFrame], Req, State, hibernate}
 	| {reply, OutFrame | [OutFrame], Req, State, hibernate}
-	| {shutdown, Req, State}
+	| {stop, Req, State}
 
 
 Types:
 Types:
 
 
@@ -125,7 +125,7 @@ Handle the data received from the Websocket connection.
 This function will be called every time data is received
 This function will be called every time data is received
 from the Websocket connection.
 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
 connection. A close reply will also result in the connection
 being closed.
 being closed.
 
 
@@ -138,7 +138,7 @@ Erlang message.
 	| {ok, Req, State, hibernate}
 	| {ok, Req, State, hibernate}
 	| {reply, OutFrame | [OutFrame], Req, State}
 	| {reply, OutFrame | [OutFrame], Req, State}
 	| {reply, OutFrame | [OutFrame], Req, State, hibernate}
 	| {reply, OutFrame | [OutFrame], Req, State, hibernate}
-	| {shutdown, Req, State}
+	| {stop, Req, State}
 
 
 Types:
 Types:
 
 
@@ -152,7 +152,7 @@ Handle the Erlang message received.
 This function will be called every time an Erlang message
 This function will be called every time an Erlang message
 has been received. The message can be any Erlang term.
 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
 connection. A close reply will also result in the connection
 being closed.
 being closed.
 
 

+ 3 - 3
src/cowboy_loop.erl

@@ -36,7 +36,7 @@
 -callback info(any(), Req, State)
 -callback info(any(), Req, State)
 	-> {ok, Req, State}
 	-> {ok, Req, State}
 	| {ok, Req, State, hibernate}
 	| {ok, Req, State, hibernate}
-	| {shutdown, Req, State}
+	| {stop, Req, State}
 	when Req::cowboy_req:req(), State::any().
 	when Req::cowboy_req:req(), State::any().
 %% @todo optional -callback terminate(terminate_reason(), cowboy_req:req(), state()) -> ok.
 %% @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);
 			after_call(Req2, State, Handler, HandlerState2);
 		{ok, Req2, HandlerState2, hibernate} ->
 		{ok, Req2, HandlerState2, hibernate} ->
 			after_call(Req2, State#state{hibernate=true}, Handler, HandlerState2);
 			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 ->
 	catch Class:Reason ->
 		Stacktrace = erlang:get_stacktrace(),
 		Stacktrace = erlang:get_stacktrace(),
 		if RespSent -> ok; true ->
 		if RespSent -> ok; true ->

+ 20 - 21
src/cowboy_websocket.erl

@@ -33,7 +33,7 @@
 -type frag_state() :: undefined
 -type frag_state() :: undefined
 	| {nofin, opcode(), binary()} | {fin, opcode(), binary()}.
 	| {nofin, opcode(), binary()} | {fin, opcode(), binary()}.
 -type rsv() :: << _:3 >>.
 -type rsv() :: << _:3 >>.
--type terminate_reason() :: normal | shutdown | timeout
+-type terminate_reason() :: normal | stop | timeout
 	| remote | {remote, close_code(), binary()}
 	| remote | {remote, close_code(), binary()}
 	| {error, badencoding | badframe | closed | atom()}
 	| {error, badencoding | badframe | closed | atom()}
 	| {crash, error | exit | throw, any()}.
 	| {crash, error | exit | throw, any()}.
@@ -49,14 +49,14 @@
 	| {ok, Req, State, hibernate}
 	| {ok, Req, State, hibernate}
 	| {reply, frame() | [frame()], Req, State}
 	| {reply, frame() | [frame()], Req, State}
 	| {reply, frame() | [frame()], Req, State, hibernate}
 	| {reply, frame() | [frame()], Req, State, hibernate}
-	| {shutdown, Req, State}
+	| {stop, Req, State}
 	when Req::cowboy_req:req(), State::any().
 	when Req::cowboy_req:req(), State::any().
 -callback websocket_info(any(), Req, State)
 -callback websocket_info(any(), Req, State)
 	-> {ok, Req, State}
 	-> {ok, Req, State}
 	| {ok, Req, State, hibernate}
 	| {ok, Req, State, hibernate}
 	| {reply, frame() | [frame()], Req, State}
 	| {reply, frame() | [frame()], Req, State}
 	| {reply, frame() | [frame()], Req, State, hibernate}
 	| {reply, frame() | [frame()], Req, State, hibernate}
-	| {shutdown, Req, State}
+	| {stop, Req, State}
 	when Req::cowboy_req:req(), State::any().
 	when Req::cowboy_req:req(), State::any().
 %% @todo optional -callback terminate(terminate_reason(), cowboy_req:req(), state()) -> ok.
 %% @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
 			case websocket_send_many(Payload, State) of
 				{ok, State2} ->
 				{ok, State2} ->
 					NextState(State2, Req2, HandlerState2, RemainingData);
 					NextState(State2, Req2, HandlerState2, RemainingData);
-				{shutdown, State2} ->
-					handler_terminate(State2, Req2, HandlerState2, shutdown);
+				{stop, State2} ->
+					handler_terminate(State2, Req2, HandlerState2, stop);
 				{{error, _} = Error, State2} ->
 				{{error, _} = Error, State2} ->
 					handler_terminate(State2, Req2, HandlerState2, Error)
 					handler_terminate(State2, Req2, HandlerState2, Error)
 			end;
 			end;
@@ -592,8 +592,8 @@ handler_call(State=#state{handler=Handler}, Req, HandlerState,
 				{ok, State2} ->
 				{ok, State2} ->
 					NextState(State2#state{hibernate=true},
 					NextState(State2#state{hibernate=true},
 						Req2, HandlerState2, RemainingData);
 						Req2, HandlerState2, RemainingData);
-				{shutdown, State2} ->
-					handler_terminate(State2, Req2, HandlerState2, shutdown);
+				{stop, State2} ->
+					handler_terminate(State2, Req2, HandlerState2, stop);
 				{{error, _} = Error, State2} ->
 				{{error, _} = Error, State2} ->
 					handler_terminate(State2, Req2, HandlerState2, Error)
 					handler_terminate(State2, Req2, HandlerState2, Error)
 			end;
 			end;
@@ -601,8 +601,8 @@ handler_call(State=#state{handler=Handler}, Req, HandlerState,
 			case websocket_send(Payload, State) of
 			case websocket_send(Payload, State) of
 				{ok, State2} ->
 				{ok, State2} ->
 					NextState(State2, Req2, HandlerState2, RemainingData);
 					NextState(State2, Req2, HandlerState2, RemainingData);
-				{shutdown, State2} ->
-					handler_terminate(State2, Req2, HandlerState2, shutdown);
+				{stop, State2} ->
+					handler_terminate(State2, Req2, HandlerState2, stop);
 				{{error, _} = Error, State2} ->
 				{{error, _} = Error, State2} ->
 					handler_terminate(State2, Req2, HandlerState2, Error)
 					handler_terminate(State2, Req2, HandlerState2, Error)
 			end;
 			end;
@@ -611,13 +611,13 @@ handler_call(State=#state{handler=Handler}, Req, HandlerState,
 				{ok, State2} ->
 				{ok, State2} ->
 					NextState(State2#state{hibernate=true},
 					NextState(State2#state{hibernate=true},
 						Req2, HandlerState2, RemainingData);
 						Req2, HandlerState2, RemainingData);
-				{shutdown, State2} ->
-					handler_terminate(State2, Req2, HandlerState2, shutdown);
+				{stop, State2} ->
+					handler_terminate(State2, Req2, HandlerState2, stop);
 				{{error, _} = Error, State2} ->
 				{{error, _} = Error, State2} ->
 					handler_terminate(State2, Req2, HandlerState2, Error)
 					handler_terminate(State2, Req2, HandlerState2, Error)
 			end;
 			end;
-		{shutdown, Req2, HandlerState2} ->
-			websocket_close(State, Req2, HandlerState2, shutdown)
+		{stop, Req2, HandlerState2} ->
+			websocket_close(State, Req2, HandlerState2, stop)
 	catch Class:Reason ->
 	catch Class:Reason ->
 		_ = websocket_close(State, Req, HandlerState, {crash, Class, Reason}),
 		_ = websocket_close(State, Req, HandlerState, {crash, Class, Reason}),
 		erlang:Class([
 		erlang:Class([
@@ -652,12 +652,11 @@ websocket_deflate_frame(_, Payload, State=#state{deflate_state = Deflate}) ->
 	{Deflated1, << 1:1, 0:2 >>, State}.
 	{Deflated1, << 1:1, 0:2 >>, State}.
 
 
 -spec websocket_send(frame(), #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),
 	Opcode = websocket_opcode(Type),
 	case Transport:send(Socket, << 1:1, 0:3, Opcode:4, 0:8 >>) of
 	case Transport:send(Socket, << 1:1, 0:3, Opcode:4, 0:8 >>) of
-		ok -> {shutdown, State};
+		ok -> {stop, State};
 		Error -> {Error, State}
 		Error -> {Error, State}
 	end;
 	end;
 websocket_send(Type, State=#state{socket=Socket, transport=Transport})
 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),
 	BinLen = payload_length_to_binary(Len),
 	Transport:send(Socket,
 	Transport:send(Socket,
 		[<< 1:1, 0:3, Opcode:4, 0:1, BinLen/bits, StatusCode:16 >>, Payload]),
 		[<< 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}) ->
 websocket_send({Type, Payload0}, State=#state{socket=Socket, transport=Transport}) ->
 	Opcode = websocket_opcode(Type),
 	Opcode = websocket_opcode(Type),
 	{Payload, Rsv, State2} = websocket_deflate_frame(Opcode, iolist_to_binary(Payload0), State),
 	{Payload, Rsv, State2} = websocket_deflate_frame(Opcode, iolist_to_binary(Payload0), State),
@@ -700,13 +699,13 @@ payload_length_to_binary(N) ->
 	end.
 	end.
 
 
 -spec websocket_send_many([frame()], #state{})
 -spec websocket_send_many([frame()], #state{})
-	-> {ok, #state{}} | {shutdown, #state{}} | {{error, atom()}, #state{}}.
+	-> {ok, #state{}} | {stop, #state{}} | {{error, atom()}, #state{}}.
 websocket_send_many([], State) ->
 websocket_send_many([], State) ->
 	{ok, State};
 	{ok, State};
 websocket_send_many([Frame|Tail], State) ->
 websocket_send_many([Frame|Tail], State) ->
 	case websocket_send(Frame, State) of
 	case websocket_send(Frame, State) of
 		{ok, State2} -> websocket_send_many(Tail, State2);
 		{ok, State2} -> websocket_send_many(Tail, State2);
-		{shutdown, State2} -> {shutdown, State2};
+		{stop, State2} -> {stop, State2};
 		{Error, State2} -> {Error, State2}
 		{Error, State2} -> {Error, State2}
 	end.
 	end.
 
 
@@ -716,7 +715,7 @@ websocket_send_many([Frame|Tail], State) ->
 websocket_close(State=#state{socket=Socket, transport=Transport},
 websocket_close(State=#state{socket=Socket, transport=Transport},
 		Req, HandlerState, Reason) ->
 		Req, HandlerState, Reason) ->
 	case Reason of
 	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 >>);
 			Transport:send(Socket, << 1:1, 0:3, 8:4, 0:1, 2:7, 1000:16 >>);
 		{error, badframe} ->
 		{error, badframe} ->
 			Transport:send(Socket, << 1:1, 0:3, 8:4, 0:1, 2:7, 1002:16 >>);
 			Transport:send(Socket, << 1:1, 0:3, 8:4, 0:1, 2:7, 1002:16 >>);

+ 2 - 2
test/handlers/long_polling_h.erl

@@ -14,12 +14,12 @@ init(Req, _) ->
 	{cowboy_loop, Req, 2, 5000, hibernate}.
 	{cowboy_loop, Req, 2, 5000, hibernate}.
 
 
 info(timeout, Req, 0) ->
 info(timeout, Req, 0) ->
-	{shutdown, cowboy_req:reply(102, Req), 0};
+	{stop, cowboy_req:reply(102, Req), 0};
 info(timeout, Req, Count) ->
 info(timeout, Req, Count) ->
 	erlang:send_after(200, self(), timeout),
 	erlang:send_after(200, self(), timeout),
 	{ok, Req, Count - 1, hibernate}.
 	{ok, Req, Count - 1, hibernate}.
 
 
-terminate(shutdown, _, 0) ->
+terminate(stop, _, 0) ->
 	ok;
 	ok;
 terminate({error, overflow}, _, _) ->
 terminate({error, overflow}, _, _) ->
 	ok.
 	ok.

+ 2 - 2
test/handlers/loop_handler_body_h.erl

@@ -16,7 +16,7 @@ init(Req, _) ->
 info(timeout, Req, State) ->
 info(timeout, Req, State) ->
 	{ok, Body, Req2} = cowboy_req:body(Req),
 	{ok, Body, Req2} = cowboy_req:body(Req),
 	100000 = byte_size(Body),
 	100000 = byte_size(Body),
-	{shutdown, cowboy_req:reply(200, Req2), State}.
+	{stop, cowboy_req:reply(200, Req2), State}.
 
 
-terminate(shutdown, _, _) ->
+terminate(stop, _, _) ->
 	ok.
 	ok.

+ 1 - 1
test/handlers/loop_handler_timeout_h.erl

@@ -15,7 +15,7 @@ init(Req, _) ->
 	{cowboy_loop, Req, undefined, 200, hibernate}.
 	{cowboy_loop, Req, undefined, 200, hibernate}.
 
 
 info(timeout, Req, State) ->
 info(timeout, Req, State) ->
-	{shutdown, cowboy_req:reply(500, Req), State}.
+	{stop, cowboy_req:reply(500, Req), State}.
 
 
 terminate(timeout, _, _) ->
 terminate(timeout, _, _) ->
 	ok.
 	ok.

+ 2 - 2
test/http_SUITE_data/http_loop_stream_recv.erl

@@ -17,7 +17,7 @@ info(stream, Req, undefined) ->
 stream(Req, ID, Acc) ->
 stream(Req, ID, Acc) ->
 	case cowboy_req:body(Req) of
 	case cowboy_req:body(Req) of
 		{ok, <<>>, Req2} ->
 		{ok, <<>>, Req2} ->
-			{shutdown, cowboy_req:reply(200, Req2), undefined};
+			{stop, cowboy_req:reply(200, Req2), undefined};
 		{_, Data, Req2} ->
 		{_, Data, Req2} ->
 			parse_id(Req2, ID, << Acc/binary, Data/binary >>)
 			parse_id(Req2, ID, << Acc/binary, Data/binary >>)
 	end.
 	end.
@@ -30,5 +30,5 @@ parse_id(Req, ID, Data) ->
 			stream(Req, ID, Data)
 			stream(Req, ID, Data)
 	end.
 	end.
 
 
-terminate(shutdown, _, _) ->
+terminate(stop, _, _) ->
 	ok.
 	ok.