diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/cowboy_app.erl | 6 | ||||
-rw-r--r-- | src/cowboy_clock.erl | 8 | ||||
-rw-r--r-- | src/cowboy_spdy.erl | 23 | ||||
-rw-r--r-- | src/cowboy_static.erl | 1 | ||||
-rw-r--r-- | src/cowboy_sup.erl | 2 |
6 files changed, 38 insertions, 4 deletions
@@ -4,6 +4,8 @@ PROJECT = cowboy # 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 CT_SUITES = eunit http spdy ws PLT_APPS = crypto public_key ssl diff --git a/src/cowboy_app.erl b/src/cowboy_app.erl index f20caf2..1161d91 100644 --- a/src/cowboy_app.erl +++ b/src/cowboy_app.erl @@ -18,8 +18,10 @@ -export([start/2]). -export([stop/1]). -start(_Type, _Args) -> +-spec start(_, _) -> {ok, pid()}. +start(_, _) -> cowboy_sup:start_link(). -stop(_State) -> +-spec stop(_) -> ok. +stop(_) -> ok. diff --git a/src/cowboy_clock.erl b/src/cowboy_clock.erl index a8de9bb..2de3470 100644 --- a/src/cowboy_clock.erl +++ b/src/cowboy_clock.erl @@ -59,6 +59,7 @@ rfc1123(DateTime) -> %% gen_server. +-spec init([]) -> {ok, #state{}}. init([]) -> ?MODULE = ets:new(?MODULE, [set, protected, named_table, {read_concurrency, true}]), @@ -68,15 +69,20 @@ init([]) -> ets:insert(?MODULE, {rfc1123, B}), {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}) -> {ok, cancel} = timer:cancel(TRef), {stop, normal, stopped, State}; handle_call(_Request, _From, State) -> {reply, ignored, State}. +-spec handle_cast(_, State) -> {noreply, State} when State::#state{}. handle_cast(_Msg, State) -> {noreply, State}. +-spec handle_info(any(), State) -> {noreply, State} when State::#state{}. handle_info(update, #state{universaltime=Prev, rfc1123=B1, tref=TRef}) -> T = erlang:universaltime(), B2 = update_rfc1123(B1, Prev, T), @@ -85,9 +91,11 @@ handle_info(update, #state{universaltime=Prev, rfc1123=B1, tref=TRef}) -> handle_info(_Info, State) -> {noreply, State}. +-spec terminate(_, _) -> ok. terminate(_Reason, _State) -> ok. +-spec code_change(_, State, _) -> {ok, State} when State::#state{}. code_change(_OldVsn, State, _Extra) -> {ok, State}. diff --git a/src/cowboy_spdy.erl b/src/cowboy_spdy.erl index 64ec950..e5aeb21 100644 --- a/src/cowboy_spdy.erl +++ b/src/cowboy_spdy.erl @@ -37,8 +37,11 @@ -export([send/2]). -export([sendfile/2]). +-type streamid() :: non_neg_integer(). +-type socket() :: {pid(), streamid()}. + -record(child, { - streamid :: non_neg_integer(), + streamid :: streamid(), pid :: pid(), input = nofin :: fin | nofin, in_buffer = <<>> :: binary(), @@ -59,7 +62,7 @@ peer, zdef, zinf, - last_streamid = 0 :: non_neg_integer(), + last_streamid = 0 :: streamid(), children = [] :: [#child{}] }). @@ -202,6 +205,7 @@ loop(State=#state{parent=Parent, socket=Socket, transport=Transport, terminate(State) end. +-spec system_continue(_, _, #state{}) -> ok. system_continue(_, _, State) -> loop(State). @@ -209,6 +213,7 @@ system_continue(_, _, State) -> system_terminate(Reason, _, _, _) -> exit(Reason). +-spec system_code_change(Misc, _, _, _) -> {ok, Misc} when Misc::#state{}. system_code_change(Misc, _, _, _) -> {ok, Misc}. @@ -351,6 +356,11 @@ delete_child(Pid, State=#state{children=Children}) -> %% 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, Env, Middlewares, Method, Host, Path, Version, Headers) -> {Host2, Port} = cow_http:parse_fullhost(Host), @@ -404,6 +414,7 @@ resume(Env, Tail, Module, Function, Args) -> %% Reply functions used by cowboy_req. +-spec reply(socket(), binary(), cowboy:http_headers(), iodata()) -> ok. reply(Socket = {Pid, _}, Status, Headers, Body) -> _ = case iolist_size(Body) of 0 -> Pid ! {reply, Socket, Status, Headers}; @@ -411,23 +422,29 @@ reply(Socket = {Pid, _}, Status, Headers, Body) -> end, ok. +-spec stream_reply(socket(), binary(), cowboy:http_headers()) -> ok. stream_reply(Socket = {Pid, _}, Status, Headers) -> _ = Pid ! {stream_reply, Socket, Status, Headers}, ok. +-spec stream_data(socket(), iodata()) -> ok. stream_data(Socket = {Pid, _}, Data) -> _ = Pid ! {stream_data, Socket, Data}, ok. +-spec stream_close(socket()) -> ok. stream_close(Socket = {Pid, _}) -> _ = Pid ! {stream_close, Socket}, ok. %% Internal transport functions. +-spec name() -> spdy. name() -> spdy. +-spec recv(socket(), non_neg_integer(), timeout()) + -> {ok, binary()} | {error, timeout}. recv(Socket = {Pid, _}, Length, Timeout) -> _ = Pid ! {recv, Socket, self(), Length, Timeout}, receive @@ -435,12 +452,14 @@ recv(Socket = {Pid, _}, Length, Timeout) -> Ret end. +-spec send(socket(), iodata()) -> ok. send(Socket, Data) -> stream_data(Socket, Data). %% We don't wait for the result of the actual sendfile call, %% therefore we can't know how much was actually sent. %% 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) -> _ = Pid ! {sendfile, Socket, Filepath}, {ok, undefined}. diff --git a/src/cowboy_static.erl b/src/cowboy_static.erl index e979571..d10ee87 100644 --- a/src/cowboy_static.erl +++ b/src/cowboy_static.erl @@ -39,6 +39,7 @@ -type state() :: {binary(), {ok, #file_info{}} | {error, atom()}, extra()}. +-spec init(_, _, _) -> {upgrade, protocol, cowboy_rest}. init(_, _, _) -> {upgrade, protocol, cowboy_rest}. diff --git a/src/cowboy_sup.erl b/src/cowboy_sup.erl index d9d7878..cf48595 100644 --- a/src/cowboy_sup.erl +++ b/src/cowboy_sup.erl @@ -22,6 +22,8 @@ start_link() -> supervisor:start_link({local, ?MODULE}, ?MODULE, []). +-spec init([]) + -> {ok, {{supervisor:strategy(), 10, 10}, [supervisor:child_spec()]}}. init([]) -> Procs = [{cowboy_clock, {cowboy_clock, start_link, []}, permanent, 5000, worker, [cowboy_clock]}], |