juhlig 6 лет назад
Родитель
Сommit
37e64f50df

+ 1 - 0
Makefile

@@ -42,6 +42,7 @@ endif
 
 # Compile options.
 
+ERLC_OPTS += +warn_missing_spec +warn_untyped_record
 TEST_ERLC_OPTS += +'{parse_transform, eunit_autoexport}'
 
 # Dialyze the tests.

+ 1 - 0
src/ranch_acceptors_sup.erl

@@ -23,6 +23,7 @@
 start_link(Ref, NumAcceptors, Transport) ->
 	supervisor:start_link(?MODULE, [Ref, NumAcceptors, Transport]).
 
+-spec init([term()]) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
 init([Ref, NumAcceptors, Transport]) ->
 	TransOpts = ranch_server:get_transport_options(Ref),
 	Logger = maps:get(logger, TransOpts, logger),

+ 2 - 0
src/ranch_app.erl

@@ -19,10 +19,12 @@
 -export([stop/1]).
 -export([profile_output/0]).
 
+-spec start(application:start_type(), term()) -> {ok, pid()} | {error, term()}.
 start(_, _) ->
 	_ = consider_profiling(),
 	ranch_sup:start_link().
 
+-spec stop(term()) -> ok.
 stop(_) ->
 	ok.
 

+ 2 - 0
src/ranch_conns_sup.erl

@@ -306,6 +306,7 @@ wait_children(NbChildren) ->
 			ok
 	end.
 
+-spec system_continue(_, _, any()) -> no_return().
 system_continue(_, _, {State, CurConns, NbChildren, Sleepers}) ->
 	loop(State, CurConns, NbChildren, Sleepers).
 
@@ -313,6 +314,7 @@ system_continue(_, _, {State, CurConns, NbChildren, Sleepers}) ->
 system_terminate(Reason, _, _, {State, _, NbChildren, _}) ->
 	terminate(State, Reason, NbChildren).
 
+-spec system_code_change(any(), _, _, _) -> {ok, any()}.
 system_code_change(Misc, _, _, _) ->
 	{ok, Misc}.
 

+ 2 - 0
src/ranch_conns_sup_sup.erl

@@ -26,6 +26,8 @@ start_link(Ref, NumConnsSups, Transport, Protocol) ->
 		Ref, NumConnsSups, Transport, Protocol
 	}).
 
+-spec init({ranch:ref(), pos_integer(), module(), module()})
+	-> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
 init({Ref, NumConnsSups, Transport, Protocol}) ->
 	ChildSpecs = [#{
 		id => {ranch_conns_sup, N},

+ 2 - 0
src/ranch_embedded_sup.erl

@@ -24,6 +24,8 @@
 start_link(Ref, Transport, TransOpts, Protocol, ProtoOpts) ->
 	supervisor:start_link(?MODULE, {Ref, Transport, TransOpts, Protocol, ProtoOpts}).
 
+-spec init({ranch:ref(), module(), any(), module(), any()})
+	-> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
 init({Ref, Transport, TransOpts, Protocol, ProtoOpts}) ->
 	Proxy = #{id => ranch_server_proxy,
 		start => {ranch_server_proxy, start_link, []},

+ 2 - 0
src/ranch_listener_sup.erl

@@ -30,6 +30,8 @@ start_link(Ref, Transport, TransOpts, Protocol, ProtoOpts) ->
 		Ref, NumAcceptors, NumConnsSups, Transport, Protocol
 	}).
 
+-spec init({ranch:ref(), pos_integer(), pos_integer(), module(), module()})
+	-> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
 init({Ref, NumAcceptors, NumConnsSups, Transport, Protocol}) ->
 	ok = ranch_server:set_listener_sup(Ref, self()),
 	ChildSpecs = [

+ 6 - 0
src/ranch_server.erl

@@ -169,6 +169,7 @@ count_connections(Ref) ->
 
 %% gen_server.
 
+-spec init([]) -> {ok, #state{}}.
 init([]) ->
 	ConnMonitors = [{{erlang:monitor(process, Pid), Pid}, {conns_sup, Ref, Id}} ||
 		[Ref, Id, Pid] <- ets:match(?TAB, {{conns_sup, '$1', '$2'}, '$3'})],
@@ -176,6 +177,7 @@ init([]) ->
 		[Ref, Pid] <- ets:match(?TAB, {{listener_sup, '$1'}, '$2'})],
 	{ok, #state{monitors=ConnMonitors++ListenerMonitors}}.
 
+-spec handle_call(term(), {pid(), reference()}, #state{}) -> {reply, ok | ignore, #state{}}.
 handle_call({set_new_listener_opts, Ref, MaxConns, TransOpts, ProtoOpts, StartArgs}, _, State) ->
 	ets:insert_new(?TAB, {{max_conns, Ref}, MaxConns}),
 	ets:insert_new(?TAB, {{trans_opts, Ref}, TransOpts}),
@@ -205,9 +207,11 @@ handle_call({set_proto_opts, Ref, Opts}, _, State) ->
 handle_call(_Request, _From, State) ->
 	{reply, ignore, State}.
 
+-spec handle_cast(_, #state{}) -> {noreply, #state{}}.
 handle_cast(_Request, State) ->
 	{noreply, State}.
 
+-spec handle_info(term(), #state{}) -> {noreply, #state{}}.
 handle_info({'DOWN', MonitorRef, process, Pid, Reason},
 		State=#state{monitors=Monitors}) ->
 	{_, TypeRef} = lists:keyfind({MonitorRef, Pid}, 1, Monitors),
@@ -227,9 +231,11 @@ handle_info({'DOWN', MonitorRef, process, Pid, Reason},
 handle_info(_Info, State) ->
 	{noreply, State}.
 
+-spec terminate(_, #state{}) -> ok.
 terminate(_Reason, _State) ->
 	ok.
 
+-spec code_change(term() | {down, term()}, #state{}, term()) -> {ok, term()}.
 code_change(_OldVsn, State, _Extra) ->
 	{ok, State}.
 

+ 6 - 0
src/ranch_server_proxy.erl

@@ -23,9 +23,11 @@
 -export([handle_info/2]).
 -export([code_change/3]).
 
+-spec start_link() -> {ok, pid()} | {error, term()}.
 start_link() ->
 	gen_server:start_link(?MODULE, [], []).
 
+-spec init([]) -> {ok, pid()} | {stop, term()}.
 init([]) ->
 	case wait_ranch_server(50) of
 		{ok, Monitor} ->
@@ -34,17 +36,21 @@ init([]) ->
 			{stop, Reason}
 	end.
 
+-spec handle_call(_, _, reference()) -> {noreply, reference(), hibernate}.
 handle_call(_, _, Monitor) ->
 	{noreply, Monitor, hibernate}.
 
+-spec handle_cast(_, reference()) -> {noreply, reference(), hibernate}.
 handle_cast(_, Monitor) ->
 	{noreply, Monitor, hibernate}.
 
+-spec handle_info(term(), reference()) -> {noreply, reference(), hibernate} | {stop, term(), reference()}.
 handle_info({'DOWN', Monitor, process, _, Reason}, Monitor) ->
 	{stop, Reason, Monitor};
 handle_info(_, Monitor) ->
 	{noreply, Monitor, hibernate}.
 
+-spec code_change(term() | {down, term()}, reference(), term()) -> {ok, reference()}.
 code_change(_, Monitor, _) ->
 	{ok, Monitor}.
 

+ 3 - 0
src/ranch_ssl.erl

@@ -90,12 +90,14 @@
 -type opts() :: [opt()].
 -export_type([opts/0]).
 
+-spec name() -> ssl.
 name() -> ssl.
 
 -spec secure() -> boolean().
 secure() ->
 	true.
 
+-spec messages() -> {ssl, ssl_closed, ssl_error, ssl_passive}.
 messages() -> {ssl, ssl_closed, ssl_error, ssl_passive}.
 
 -spec listen(ranch:transport_opts(opts())) -> {ok, ssl:sslsocket()} | {error, atom()}.
@@ -125,6 +127,7 @@ do_listen(SocketOpts0, Logger) ->
 
 %% 'binary' and 'list' are disallowed but they are handled
 %% specifically as they do not have 2-tuple equivalents.
+-spec disallowed_listen_options() -> [atom()].
 disallowed_listen_options() ->
 	[alpn_advertised_protocols, client_preferred_next_protocols,
 		fallback, server_name_indication, srp_identity

+ 1 - 0
src/ranch_sup.erl

@@ -22,6 +22,7 @@
 start_link() ->
 	supervisor:start_link({local, ?MODULE}, ?MODULE, []).
 
+-spec init([]) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
 init([]) ->
 	Intensity = case application:get_env(ranch_sup_intensity) of
 		{ok, Value1} -> Value1;

+ 3 - 0
src/ranch_tcp.erl

@@ -70,12 +70,14 @@
 -type opts() :: [opt()].
 -export_type([opts/0]).
 
+-spec name() -> tcp.
 name() -> tcp.
 
 -spec secure() -> boolean().
 secure() ->
 	false.
 
+-spec messages() -> {tcp, tcp_closed, tcp_error, tcp_passive}.
 messages() -> {tcp, tcp_closed, tcp_error, tcp_passive}.
 
 -spec listen(ranch:transport_opts(opts())) -> {ok, inet:socket()} | {error, atom()}.
@@ -94,6 +96,7 @@ listen(TransOpts) ->
 
 %% 'binary' and 'list' are disallowed but they are handled
 %% specifically as they do not have 2-tuple equivalents.
+-spec disallowed_listen_options() -> [atom()].
 disallowed_listen_options() ->
 	[active, header, mode, packet, packet_size, line_delimiter, reuseaddr].