aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-10-11 01:49:13 +0200
committerLoïc Hoguin <[email protected]>2011-10-11 01:49:13 +0200
commit691b7c45184ec2b5a901ecbac7fcc633e06c35e4 (patch)
treeaf1183a1fbc8eeae07ce7dee767c7fe2cc6dad13 /src
parent5e006be01fb9af2cbb6b62bec695a2c160733cf4 (diff)
downloadcowboy-691b7c45184ec2b5a901ecbac7fcc633e06c35e4.tar.gz
cowboy-691b7c45184ec2b5a901ecbac7fcc633e06c35e4.tar.bz2
cowboy-691b7c45184ec2b5a901ecbac7fcc633e06c35e4.zip
Fix specs after erlang:hibernate/3 calls were added
This however does not fix the related Dialyzer warnings. I have no idea what the warnings are about nor how to fix them, so feel free to work on it and submit a patch!
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_http_protocol.erl31
-rw-r--r--src/cowboy_http_websocket.erl20
2 files changed, 26 insertions, 25 deletions
diff --git a/src/cowboy_http_protocol.erl b/src/cowboy_http_protocol.erl
index 290007b..ef6d227 100644
--- a/src/cowboy_http_protocol.erl
+++ b/src/cowboy_http_protocol.erl
@@ -64,7 +64,7 @@ start_link(ListenerPid, Socket, Transport, Opts) ->
%% FSM.
%% @private
--spec init(pid(), inet:socket(), module(), any()) -> ok.
+-spec init(pid(), inet:socket(), module(), any()) -> ok | none().
init(ListenerPid, Socket, Transport, Opts) ->
Dispatch = proplists:get_value(dispatch, Opts, []),
MaxEmptyLines = proplists:get_value(max_empty_lines, Opts, 5),
@@ -74,7 +74,7 @@ init(ListenerPid, Socket, Transport, Opts) ->
dispatch=Dispatch, max_empty_lines=MaxEmptyLines, timeout=Timeout}).
%% @private
--spec parse_request(#state{}) -> ok.
+-spec parse_request(#state{}) -> ok | none().
%% @todo Use decode_packet options to limit length?
parse_request(State=#state{buffer=Buffer}) ->
case erlang:decode_packet(http_bin, Buffer, []) of
@@ -83,7 +83,7 @@ parse_request(State=#state{buffer=Buffer}) ->
{error, _Reason} -> error_terminate(400, State)
end.
--spec wait_request(#state{}) -> ok.
+-spec wait_request(#state{}) -> ok | none().
wait_request(State=#state{socket=Socket, transport=Transport,
timeout=T, buffer=Buffer}) ->
case Transport:recv(Socket, 0, T) of
@@ -93,7 +93,7 @@ wait_request(State=#state{socket=Socket, transport=Transport,
end.
-spec request({http_request, http_method(), http_uri(),
- http_version()}, #state{}) -> ok.
+ http_version()}, #state{}) -> ok | none().
%% @todo We probably want to handle some things differently between versions.
request({http_request, _Method, _URI, Version}, State)
when Version =/= {1, 0}, Version =/= {1, 1} ->
@@ -122,7 +122,7 @@ request({http_error, <<"\r\n">>}, State=#state{req_empty_lines=N}) ->
request({http_error, _Any}, State) ->
error_terminate(400, State).
--spec parse_header(#http_req{}, #state{}) -> ok.
+-spec parse_header(#http_req{}, #state{}) -> ok | none().
parse_header(Req, State=#state{buffer=Buffer}) ->
case erlang:decode_packet(httph_bin, Buffer, []) of
{ok, Header, Rest} -> header(Header, Req, State#state{buffer=Rest});
@@ -130,7 +130,7 @@ parse_header(Req, State=#state{buffer=Buffer}) ->
{error, _Reason} -> error_terminate(400, State)
end.
--spec wait_header(#http_req{}, #state{}) -> ok.
+-spec wait_header(#http_req{}, #state{}) -> ok | none().
wait_header(Req, State=#state{socket=Socket,
transport=Transport, timeout=T, buffer=Buffer}) ->
case Transport:recv(Socket, 0, T) of
@@ -141,7 +141,7 @@ wait_header(Req, State=#state{socket=Socket,
end.
-spec header({http_header, integer(), http_header(), any(), binary()}
- | http_eoh, #http_req{}, #state{}) -> ok.
+ | http_eoh, #http_req{}, #state{}) -> ok | none().
header({http_header, _I, 'Host', _R, RawHost}, Req=#http_req{
transport=Transport, host=undefined}, State) ->
RawHost2 = cowboy_bstr:to_lower(RawHost),
@@ -187,7 +187,7 @@ header({http_error, _Bin}, _Req, State) ->
error_terminate(500, State).
-spec dispatch(fun((#http_req{}, #state{}) -> ok),
- #http_req{}, #state{}) -> ok.
+ #http_req{}, #state{}) -> ok | none().
dispatch(Next, Req=#http_req{host=Host, path=Path},
State=#state{dispatch=Dispatch}) ->
%% @todo We probably want to filter the Host and Path here to allow
@@ -202,7 +202,7 @@ dispatch(Next, Req=#http_req{host=Host, path=Path},
error_terminate(404, State)
end.
--spec handler_init(#http_req{}, #state{}) -> ok.
+-spec handler_init(#http_req{}, #state{}) -> ok | none().
handler_init(Req, State=#state{listener=ListenerPid,
transport=Transport, handler={Handler, Opts}}) ->
try Handler:init({Transport:name(), http}, Req, Opts) of
@@ -234,7 +234,7 @@ handler_init(Req, State=#state{listener=ListenerPid,
[Handler, Class, Reason, Opts, Req, erlang:get_stacktrace()])
end.
--spec handler_handle(any(), #http_req{}, #state{}) -> ok.
+-spec handler_handle(any(), #http_req{}, #state{}) -> ok | none().
handler_handle(HandlerState, Req, State=#state{handler={Handler, Opts}}) ->
try Handler:handle(Req, HandlerState) of
{ok, Req2, HandlerState2} ->
@@ -253,10 +253,11 @@ handler_handle(HandlerState, Req, State=#state{handler={Handler, Opts}}) ->
%% We don't listen for Transport closes because that would force us
%% to receive data and buffer it indefinitely.
--spec handler_before_loop(any(), #http_req{}, #state{}) -> ok.
+-spec handler_before_loop(any(), #http_req{}, #state{}) -> ok | none().
handler_before_loop(HandlerState, Req, State=#state{hibernate=true}) ->
State2 = handler_loop_timeout(State),
- erlang:hibernate(?MODULE, handler_loop, [HandlerState, Req, State2]);
+ erlang:hibernate(?MODULE, handler_loop,
+ [HandlerState, Req, State2#state{hibernate=false}]);
handler_before_loop(HandlerState, Req, State) ->
State2 = handler_loop_timeout(State),
handler_loop(HandlerState, Req, State2).
@@ -273,7 +274,7 @@ handler_loop_timeout(State=#state{loop_timeout=Timeout,
erlang:send_after(Timeout, self(), {?MODULE, timeout, TRef}),
State#state{loop_timeout_ref=TRef}.
--spec handler_loop(any(), #http_req{}, #state{}) -> ok.
+-spec handler_loop(any(), #http_req{}, #state{}) -> ok | none().
handler_loop(HandlerState, Req, State=#state{loop_timeout_ref=TRef}) ->
receive
{?MODULE, timeout, TRef} ->
@@ -284,7 +285,7 @@ handler_loop(HandlerState, Req, State=#state{loop_timeout_ref=TRef}) ->
handler_call(HandlerState, Req, State, Message)
end.
--spec handler_call(any(), #http_req{}, #state{}, any()) -> ok.
+-spec handler_call(any(), #http_req{}, #state{}, any()) -> ok | none().
handler_call(HandlerState, Req, State=#state{handler={Handler, Opts}},
Message) ->
try Handler:info(Message, Req, HandlerState) of
@@ -319,7 +320,7 @@ handler_terminate(HandlerState, Req, #state{handler={Handler, Opts}}) ->
HandlerState, Req, erlang:get_stacktrace()])
end.
--spec next_request(any(), #http_req{}, #state{}) -> ok.
+-spec next_request(any(), #http_req{}, #state{}) -> ok | none().
next_request(HandlerState, Req=#http_req{connection=Conn, buffer=Buffer},
State) ->
HandlerRes = handler_terminate(HandlerState, Req, State),
diff --git a/src/cowboy_http_websocket.erl b/src/cowboy_http_websocket.erl
index 039e2b6..d3c9c2d 100644
--- a/src/cowboy_http_websocket.erl
+++ b/src/cowboy_http_websocket.erl
@@ -64,7 +64,7 @@
%% You do not need to call this function manually. To upgrade to the WebSocket
%% protocol, you simply need to return <em>{upgrade, protocol, {@module}}</em>
%% in your <em>cowboy_http_handler:init/3</em> handler function.
--spec upgrade(pid(), module(), any(), #http_req{}) -> ok.
+-spec upgrade(pid(), module(), any(), #http_req{}) -> ok | none().
upgrade(ListenerPid, Handler, Opts, Req) ->
cowboy_listener:move_connection(ListenerPid, websocket, self()),
case catch websocket_upgrade(#state{handler=Handler, opts=Opts}, Req) of
@@ -110,7 +110,7 @@ websocket_upgrade(<< Version >>, State, Req)
{ok, State#state{version=Version - $0, origin=Origin,
challenge=Challenge}, Req4}.
--spec handler_init(#state{}, #http_req{}) -> ok.
+-spec handler_init(#state{}, #http_req{}) -> ok | none().
handler_init(State=#state{handler=Handler, opts=Opts},
Req=#http_req{transport=Transport}) ->
try Handler:websocket_init(Transport:name(), Req, Opts) of
@@ -160,7 +160,7 @@ upgrade_denied(Req=#http_req{socket=Socket, transport=Transport,
upgrade_terminate(#http_req{socket=Socket, transport=Transport}) ->
Transport:close(Socket).
--spec websocket_handshake(#state{}, #http_req{}, any()) -> ok.
+-spec websocket_handshake(#state{}, #http_req{}, any()) -> ok | none().
websocket_handshake(State=#state{version=0, origin=Origin,
challenge=Challenge}, Req=#http_req{transport=Transport,
raw_host=Host, port=Port, raw_path=Path, raw_qs=QS}, HandlerState) ->
@@ -185,7 +185,7 @@ websocket_handshake(State=#state{challenge=Challenge},
handler_before_loop(State#state{messages=Transport:messages()},
Req2, HandlerState, <<>>).
--spec handler_before_loop(#state{}, #http_req{}, any(), binary()) -> ok.
+-spec handler_before_loop(#state{}, #http_req{}, any(), binary()) -> ok | none().
handler_before_loop(State=#state{hibernate=true},
Req=#http_req{socket=Socket, transport=Transport},
HandlerState, SoFar) ->
@@ -210,7 +210,7 @@ handler_loop_timeout(State=#state{timeout=Timeout, timeout_ref=PrevRef}) ->
State#state{timeout_ref=TRef}.
%% @private
--spec handler_loop(#state{}, #http_req{}, any(), binary()) -> ok.
+-spec handler_loop(#state{}, #http_req{}, any(), binary()) -> ok | none().
handler_loop(State=#state{messages={OK, Closed, Error}, timeout_ref=TRef},
Req=#http_req{socket=Socket}, HandlerState, SoFar) ->
receive
@@ -230,7 +230,7 @@ handler_loop(State=#state{messages={OK, Closed, Error}, timeout_ref=TRef},
SoFar, websocket_info, Message, fun handler_before_loop/4)
end.
--spec websocket_data(#state{}, #http_req{}, any(), binary()) -> ok.
+-spec websocket_data(#state{}, #http_req{}, any(), binary()) -> ok | none().
%% No more data.
websocket_data(State, Req, HandlerState, <<>>) ->
handler_before_loop(State, Req, HandlerState, <<>>);
@@ -284,14 +284,14 @@ websocket_data(State, Req, HandlerState, _Bad) ->
%% hybi unmasking.
-spec websocket_unmask(#state{}, #http_req{}, any(), binary(),
- opcode(), binary(), mask_key()) -> ok.
+ opcode(), binary(), mask_key()) -> ok | none().
websocket_unmask(State, Req, HandlerState, RemainingData,
Opcode, Payload, MaskKey) ->
websocket_unmask(State, Req, HandlerState, RemainingData,
Opcode, Payload, MaskKey, <<>>).
-spec websocket_unmask(#state{}, #http_req{}, any(), binary(),
- opcode(), binary(), mask_key(), binary()) -> ok.
+ opcode(), binary(), mask_key(), binary()) -> ok | none().
websocket_unmask(State, Req, HandlerState, RemainingData,
Opcode, << O:32, Rest/bits >>, MaskKey, Acc) ->
T = O bxor MaskKey,
@@ -322,7 +322,7 @@ websocket_unmask(State, Req, HandlerState, RemainingData,
%% hybi dispatching.
-spec websocket_dispatch(#state{}, #http_req{}, any(), binary(),
- opcode(), binary()) -> ok.
+ opcode(), binary()) -> ok | none().
%% @todo Fragmentation.
%~ websocket_dispatch(State, Req, HandlerState, RemainingData, 0, Payload) ->
%% Text frame.
@@ -350,7 +350,7 @@ websocket_dispatch(State, Req, HandlerState, RemainingData, 10, Payload) ->
websocket_handle, {pong, Payload}, fun websocket_data/4).
-spec handler_call(#state{}, #http_req{}, any(), binary(),
- atom(), any(), fun()) -> ok.
+ atom(), any(), fun()) -> ok | none().
handler_call(State=#state{handler=Handler, opts=Opts}, Req, HandlerState,
RemainingData, Callback, Message, NextState) ->
try Handler:Callback(Message, Req, HandlerState) of