mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
Add +warn_missing_spec and fix specs
This commit is contained in:
parent
17af50812c
commit
c9b9644aa3
6 changed files with 38 additions and 4 deletions
2
Makefile
2
Makefile
|
@ -4,6 +4,8 @@ PROJECT = cowboy
|
||||||
|
|
||||||
# Options.
|
# Options.
|
||||||
|
|
||||||
|
ERLC_OPTS ?= -Werror +debug_info +warn_export_all +warn_export_vars \
|
||||||
|
+warn_shadow_vars +warn_obsolete_guard +warn_missing_spec
|
||||||
COMPILE_FIRST = cowboy_middleware cowboy_sub_protocol
|
COMPILE_FIRST = cowboy_middleware cowboy_sub_protocol
|
||||||
CT_SUITES = eunit http spdy ws
|
CT_SUITES = eunit http spdy ws
|
||||||
PLT_APPS = crypto public_key ssl
|
PLT_APPS = crypto public_key ssl
|
||||||
|
|
|
@ -18,8 +18,10 @@
|
||||||
-export([start/2]).
|
-export([start/2]).
|
||||||
-export([stop/1]).
|
-export([stop/1]).
|
||||||
|
|
||||||
start(_Type, _Args) ->
|
-spec start(_, _) -> {ok, pid()}.
|
||||||
|
start(_, _) ->
|
||||||
cowboy_sup:start_link().
|
cowboy_sup:start_link().
|
||||||
|
|
||||||
stop(_State) ->
|
-spec stop(_) -> ok.
|
||||||
|
stop(_) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -59,6 +59,7 @@ rfc1123(DateTime) ->
|
||||||
|
|
||||||
%% gen_server.
|
%% gen_server.
|
||||||
|
|
||||||
|
-spec init([]) -> {ok, #state{}}.
|
||||||
init([]) ->
|
init([]) ->
|
||||||
?MODULE = ets:new(?MODULE, [set, protected,
|
?MODULE = ets:new(?MODULE, [set, protected,
|
||||||
named_table, {read_concurrency, true}]),
|
named_table, {read_concurrency, true}]),
|
||||||
|
@ -68,15 +69,20 @@ init([]) ->
|
||||||
ets:insert(?MODULE, {rfc1123, B}),
|
ets:insert(?MODULE, {rfc1123, B}),
|
||||||
{ok, #state{universaltime=T, rfc1123=B, tref=TRef}}.
|
{ok, #state{universaltime=T, rfc1123=B, tref=TRef}}.
|
||||||
|
|
||||||
|
-spec handle_call(any(), _, State)
|
||||||
|
-> {reply, ignored, State} | {stop, normal, stopped, State}
|
||||||
|
when State::#state{}.
|
||||||
handle_call(stop, _From, State=#state{tref=TRef}) ->
|
handle_call(stop, _From, State=#state{tref=TRef}) ->
|
||||||
{ok, cancel} = timer:cancel(TRef),
|
{ok, cancel} = timer:cancel(TRef),
|
||||||
{stop, normal, stopped, State};
|
{stop, normal, stopped, State};
|
||||||
handle_call(_Request, _From, State) ->
|
handle_call(_Request, _From, State) ->
|
||||||
{reply, ignored, State}.
|
{reply, ignored, State}.
|
||||||
|
|
||||||
|
-spec handle_cast(_, State) -> {noreply, State} when State::#state{}.
|
||||||
handle_cast(_Msg, State) ->
|
handle_cast(_Msg, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
|
-spec handle_info(any(), State) -> {noreply, State} when State::#state{}.
|
||||||
handle_info(update, #state{universaltime=Prev, rfc1123=B1, tref=TRef}) ->
|
handle_info(update, #state{universaltime=Prev, rfc1123=B1, tref=TRef}) ->
|
||||||
T = erlang:universaltime(),
|
T = erlang:universaltime(),
|
||||||
B2 = update_rfc1123(B1, Prev, T),
|
B2 = update_rfc1123(B1, Prev, T),
|
||||||
|
@ -85,9 +91,11 @@ handle_info(update, #state{universaltime=Prev, rfc1123=B1, tref=TRef}) ->
|
||||||
handle_info(_Info, State) ->
|
handle_info(_Info, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
|
-spec terminate(_, _) -> ok.
|
||||||
terminate(_Reason, _State) ->
|
terminate(_Reason, _State) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
-spec code_change(_, State, _) -> {ok, State} when State::#state{}.
|
||||||
code_change(_OldVsn, State, _Extra) ->
|
code_change(_OldVsn, State, _Extra) ->
|
||||||
{ok, State}.
|
{ok, State}.
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,11 @@
|
||||||
-export([send/2]).
|
-export([send/2]).
|
||||||
-export([sendfile/2]).
|
-export([sendfile/2]).
|
||||||
|
|
||||||
|
-type streamid() :: non_neg_integer().
|
||||||
|
-type socket() :: {pid(), streamid()}.
|
||||||
|
|
||||||
-record(child, {
|
-record(child, {
|
||||||
streamid :: non_neg_integer(),
|
streamid :: streamid(),
|
||||||
pid :: pid(),
|
pid :: pid(),
|
||||||
input = nofin :: fin | nofin,
|
input = nofin :: fin | nofin,
|
||||||
in_buffer = <<>> :: binary(),
|
in_buffer = <<>> :: binary(),
|
||||||
|
@ -59,7 +62,7 @@
|
||||||
peer,
|
peer,
|
||||||
zdef,
|
zdef,
|
||||||
zinf,
|
zinf,
|
||||||
last_streamid = 0 :: non_neg_integer(),
|
last_streamid = 0 :: streamid(),
|
||||||
children = [] :: [#child{}]
|
children = [] :: [#child{}]
|
||||||
}).
|
}).
|
||||||
|
|
||||||
|
@ -202,6 +205,7 @@ loop(State=#state{parent=Parent, socket=Socket, transport=Transport,
|
||||||
terminate(State)
|
terminate(State)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec system_continue(_, _, #state{}) -> ok.
|
||||||
system_continue(_, _, State) ->
|
system_continue(_, _, State) ->
|
||||||
loop(State).
|
loop(State).
|
||||||
|
|
||||||
|
@ -209,6 +213,7 @@ system_continue(_, _, State) ->
|
||||||
system_terminate(Reason, _, _, _) ->
|
system_terminate(Reason, _, _, _) ->
|
||||||
exit(Reason).
|
exit(Reason).
|
||||||
|
|
||||||
|
-spec system_code_change(Misc, _, _, _) -> {ok, Misc} when Misc::#state{}.
|
||||||
system_code_change(Misc, _, _, _) ->
|
system_code_change(Misc, _, _, _) ->
|
||||||
{ok, Misc}.
|
{ok, Misc}.
|
||||||
|
|
||||||
|
@ -351,6 +356,11 @@ delete_child(Pid, State=#state{children=Children}) ->
|
||||||
|
|
||||||
%% Request process.
|
%% Request process.
|
||||||
|
|
||||||
|
-spec request_init(socket(), {inet:ip_address(), inet:port_number()},
|
||||||
|
cowboy:onrequest_fun(), cowboy:onresponse_fun(),
|
||||||
|
cowboy_middleware:env(), [module()],
|
||||||
|
binary(), binary(), binary(), binary(), [{binary(), binary()}])
|
||||||
|
-> ok.
|
||||||
request_init(FakeSocket, Peer, OnRequest, OnResponse,
|
request_init(FakeSocket, Peer, OnRequest, OnResponse,
|
||||||
Env, Middlewares, Method, Host, Path, Version, Headers) ->
|
Env, Middlewares, Method, Host, Path, Version, Headers) ->
|
||||||
{Host2, Port} = cow_http:parse_fullhost(Host),
|
{Host2, Port} = cow_http:parse_fullhost(Host),
|
||||||
|
@ -404,6 +414,7 @@ resume(Env, Tail, Module, Function, Args) ->
|
||||||
|
|
||||||
%% Reply functions used by cowboy_req.
|
%% Reply functions used by cowboy_req.
|
||||||
|
|
||||||
|
-spec reply(socket(), binary(), cowboy:http_headers(), iodata()) -> ok.
|
||||||
reply(Socket = {Pid, _}, Status, Headers, Body) ->
|
reply(Socket = {Pid, _}, Status, Headers, Body) ->
|
||||||
_ = case iolist_size(Body) of
|
_ = case iolist_size(Body) of
|
||||||
0 -> Pid ! {reply, Socket, Status, Headers};
|
0 -> Pid ! {reply, Socket, Status, Headers};
|
||||||
|
@ -411,23 +422,29 @@ reply(Socket = {Pid, _}, Status, Headers, Body) ->
|
||||||
end,
|
end,
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
-spec stream_reply(socket(), binary(), cowboy:http_headers()) -> ok.
|
||||||
stream_reply(Socket = {Pid, _}, Status, Headers) ->
|
stream_reply(Socket = {Pid, _}, Status, Headers) ->
|
||||||
_ = Pid ! {stream_reply, Socket, Status, Headers},
|
_ = Pid ! {stream_reply, Socket, Status, Headers},
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
-spec stream_data(socket(), iodata()) -> ok.
|
||||||
stream_data(Socket = {Pid, _}, Data) ->
|
stream_data(Socket = {Pid, _}, Data) ->
|
||||||
_ = Pid ! {stream_data, Socket, Data},
|
_ = Pid ! {stream_data, Socket, Data},
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
-spec stream_close(socket()) -> ok.
|
||||||
stream_close(Socket = {Pid, _}) ->
|
stream_close(Socket = {Pid, _}) ->
|
||||||
_ = Pid ! {stream_close, Socket},
|
_ = Pid ! {stream_close, Socket},
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
%% Internal transport functions.
|
%% Internal transport functions.
|
||||||
|
|
||||||
|
-spec name() -> spdy.
|
||||||
name() ->
|
name() ->
|
||||||
spdy.
|
spdy.
|
||||||
|
|
||||||
|
-spec recv(socket(), non_neg_integer(), timeout())
|
||||||
|
-> {ok, binary()} | {error, timeout}.
|
||||||
recv(Socket = {Pid, _}, Length, Timeout) ->
|
recv(Socket = {Pid, _}, Length, Timeout) ->
|
||||||
_ = Pid ! {recv, Socket, self(), Length, Timeout},
|
_ = Pid ! {recv, Socket, self(), Length, Timeout},
|
||||||
receive
|
receive
|
||||||
|
@ -435,12 +452,14 @@ recv(Socket = {Pid, _}, Length, Timeout) ->
|
||||||
Ret
|
Ret
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec send(socket(), iodata()) -> ok.
|
||||||
send(Socket, Data) ->
|
send(Socket, Data) ->
|
||||||
stream_data(Socket, Data).
|
stream_data(Socket, Data).
|
||||||
|
|
||||||
%% We don't wait for the result of the actual sendfile call,
|
%% We don't wait for the result of the actual sendfile call,
|
||||||
%% therefore we can't know how much was actually sent.
|
%% therefore we can't know how much was actually sent.
|
||||||
%% This isn't a problem as we don't use this value in Cowboy.
|
%% This isn't a problem as we don't use this value in Cowboy.
|
||||||
|
-spec sendfile(socket(), file:name_all()) -> {ok, undefined}.
|
||||||
sendfile(Socket = {Pid, _}, Filepath) ->
|
sendfile(Socket = {Pid, _}, Filepath) ->
|
||||||
_ = Pid ! {sendfile, Socket, Filepath},
|
_ = Pid ! {sendfile, Socket, Filepath},
|
||||||
{ok, undefined}.
|
{ok, undefined}.
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
-type state() :: {binary(), {ok, #file_info{}} | {error, atom()}, extra()}.
|
-type state() :: {binary(), {ok, #file_info{}} | {error, atom()}, extra()}.
|
||||||
|
|
||||||
|
-spec init(_, _, _) -> {upgrade, protocol, cowboy_rest}.
|
||||||
init(_, _, _) ->
|
init(_, _, _) ->
|
||||||
{upgrade, protocol, cowboy_rest}.
|
{upgrade, protocol, cowboy_rest}.
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
start_link() ->
|
start_link() ->
|
||||||
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
||||||
|
|
||||||
|
-spec init([])
|
||||||
|
-> {ok, {{supervisor:strategy(), 10, 10}, [supervisor:child_spec()]}}.
|
||||||
init([]) ->
|
init([]) ->
|
||||||
Procs = [{cowboy_clock, {cowboy_clock, start_link, []},
|
Procs = [{cowboy_clock, {cowboy_clock, start_link, []},
|
||||||
permanent, 5000, worker, [cowboy_clock]}],
|
permanent, 5000, worker, [cowboy_clock]}],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue