diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ranch.app.src | 2 | ||||
-rw-r--r-- | src/ranch.erl | 8 | ||||
-rw-r--r-- | src/ranch_acceptor.erl | 7 | ||||
-rw-r--r-- | src/ranch_acceptors_sup.erl | 14 | ||||
-rw-r--r-- | src/ranch_app.erl | 14 | ||||
-rw-r--r-- | src/ranch_conns_sup.erl | 15 | ||||
-rw-r--r-- | src/ranch_listener.erl | 29 | ||||
-rw-r--r-- | src/ranch_listener_sup.erl | 8 | ||||
-rw-r--r-- | src/ranch_ssl.erl | 23 | ||||
-rw-r--r-- | src/ranch_sup.erl | 14 | ||||
-rw-r--r-- | src/ranch_tcp.erl | 21 |
11 files changed, 96 insertions, 59 deletions
diff --git a/src/ranch.app.src b/src/ranch.app.src index 6501cb0..88e1362 100644 --- a/src/ranch.app.src +++ b/src/ranch.app.src @@ -14,7 +14,7 @@ {application, ranch, [ {description, "Socket acceptor pool for TCP protocols."}, - {vsn, "0.2.0"}, + {vsn, "0.2.1"}, {modules, []}, {registered, [ranch_sup]}, {applications, [ diff --git a/src/ranch.erl b/src/ranch.erl index ab9d767..b6008fa 100644 --- a/src/ranch.erl +++ b/src/ranch.erl @@ -15,8 +15,12 @@ %% @doc Ranch API to start and stop listeners. -module(ranch). --export([start_listener/6, stop_listener/1, child_spec/6, accept_ack/1, - get_protocol_options/1, set_protocol_options/2]). +-export([start_listener/6]). +-export([stop_listener/1]). +-export([child_spec/6]). +-export([accept_ack/1]). +-export([get_protocol_options/1]). +-export([set_protocol_options/2]). %% @doc Start a listener for the given transport and protocol. %% diff --git a/src/ranch_acceptor.erl b/src/ranch_acceptor.erl index f35b025..8de0de7 100644 --- a/src/ranch_acceptor.erl +++ b/src/ranch_acceptor.erl @@ -15,8 +15,11 @@ %% @private -module(ranch_acceptor). --export([start_link/6]). %% API. --export([acceptor/7]). %% Internal. +%% API. +-export([start_link/6]). + +%% Internal. +-export([acceptor/7]). %% API. diff --git a/src/ranch_acceptors_sup.erl b/src/ranch_acceptors_sup.erl index 3b32668..963b4d3 100644 --- a/src/ranch_acceptors_sup.erl +++ b/src/ranch_acceptors_sup.erl @@ -16,8 +16,11 @@ -module(ranch_acceptors_sup). -behaviour(supervisor). --export([start_link/7]). %% API. --export([init/1]). %% supervisor. +%% API. +-export([start_link/7]). + +%% supervisor. +-export([init/1]). %% API. @@ -30,13 +33,6 @@ start_link(NbAcceptors, Transport, TransOpts, %% supervisor. --spec init([any()]) -> {'ok', {{'one_for_one', 10, 10}, [{ - any(), {atom() | tuple(), atom(), 'undefined' | [any()]}, - 'permanent' | 'temporary' | 'transient', - 'brutal_kill' | 'infinity' | non_neg_integer(), - 'supervisor' | 'worker', - 'dynamic' | [atom() | tuple()]}] -}}. init([NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts, ListenerPid, ConnsPid]) -> {ok, LSocket} = Transport:listen(TransOpts), diff --git a/src/ranch_app.erl b/src/ranch_app.erl index 0dc687c..2402de6 100644 --- a/src/ranch_app.erl +++ b/src/ranch_app.erl @@ -16,20 +16,18 @@ -module(ranch_app). -behaviour(application). --export([start/2, stop/1, profile_output/0]). %% API. - --type application_start_type() :: normal - | {takeover, node()} | {failover, node()}. +%% API. +-export([start/2]). +-export([stop/1]). +-export([profile_output/0]). %% API. --spec start(application_start_type(), any()) -> {ok, pid()}. -start(_Type, _Args) -> +start(_, _) -> consider_profiling(), ranch_sup:start_link(). --spec stop(any()) -> ok. -stop(_State) -> +stop(_) -> ok. -spec profile_output() -> ok. diff --git a/src/ranch_conns_sup.erl b/src/ranch_conns_sup.erl index 41c1919..99853c5 100644 --- a/src/ranch_conns_sup.erl +++ b/src/ranch_conns_sup.erl @@ -16,8 +16,12 @@ -module(ranch_conns_sup). -behaviour(supervisor). --export([start_link/0, start_protocol/5]). %% API. --export([init/1]). %% supervisor. +%% API. +-export([start_link/0]). +-export([start_protocol/5]). + +%% supervisor. +-export([init/1]). %% API. @@ -32,13 +36,6 @@ start_protocol(ListenerPid, Socket, Transport, Protocol, Opts) -> %% supervisor. --spec init([]) -> {'ok', {{'simple_one_for_one', 0, 1}, [{ - any(), {atom() | tuple(), atom(), 'undefined' | [any()]}, - 'permanent' | 'temporary' | 'transient', - 'brutal_kill' | 'infinity' | non_neg_integer(), - 'supervisor' | 'worker', - 'dynamic' | [atom() | tuple()]}] -}}. init([]) -> {ok, {{simple_one_for_one, 0, 1}, [{?MODULE, {?MODULE, start_protocol, []}, temporary, brutal_kill, worker, [?MODULE]}]}}. diff --git a/src/ranch_listener.erl b/src/ranch_listener.erl index fbcb87a..8a78472 100644 --- a/src/ranch_listener.erl +++ b/src/ranch_listener.erl @@ -16,11 +16,23 @@ -module(ranch_listener). -behaviour(gen_server). --export([start_link/2, stop/1, - add_connection/4, move_connection/3, remove_connection/2, check_upgrades/2, - get_protocol_options/1, set_protocol_options/2]). %% API. --export([init/1, handle_call/3, handle_cast/2, - handle_info/2, terminate/2, code_change/3]). %% gen_server. +%% API. +-export([start_link/2]). +-export([stop/1]). +-export([add_connection/4]). +-export([move_connection/3]). +-export([remove_connection/2]). +-export([check_upgrades/2]). +-export([get_protocol_options/1]). +-export([set_protocol_options/2]). + +%% gen_server. +-export([init/1]). +-export([handle_call/3]). +-export([handle_cast/2]). +-export([handle_info/2]). +-export([terminate/2]). +-export([code_change/3]). -type pools() :: [{atom(), non_neg_integer()}]. @@ -103,7 +115,6 @@ set_protocol_options(ServerPid, ProtoOpts) -> %% gen_server. %% @private --spec init(list()) -> {ok, #state{}}. init([MaxConns, ProtoOpts]) -> ConnsTable = ets:new(connections_table, [set, private]), Queue = queue:new(), @@ -111,8 +122,6 @@ init([MaxConns, ProtoOpts]) -> proto_opts=ProtoOpts, queue=Queue}}. %% @private --spec handle_call(_, _, State) - -> {reply, ignored, State} | {stop, normal, stopped, State}. handle_call({add_connection, Pool, ConnPid, AccOptsVsn}, From, State=#state{ conn_pools=Pools, conns_table=ConnsTable, queue=Queue, max_conns=MaxConns, @@ -145,7 +154,6 @@ handle_call(_, _From, State) -> {reply, ignored, State}. %% @private --spec handle_cast(_, State) -> {noreply, State}. handle_cast({move_connection, DestPool, ConnPid}, State=#state{ conn_pools=Pools, conns_table=ConnsTable}) -> Pools2 = move_pid(ConnPid, DestPool, Pools, ConnsTable), @@ -158,7 +166,6 @@ handle_cast(_Msg, State) -> {noreply, State}. %% @private --spec handle_info(_, State) -> {noreply, State}. handle_info({'DOWN', _Ref, process, Pid, _Info}, State=#state{ conn_pools=Pools, conns_table=ConnsTable, queue=Queue}) -> {Pools2, Queue2} = remove_pid(Pid, Pools, ConnsTable, Queue), @@ -167,12 +174,10 @@ handle_info(_Info, State) -> {noreply, State}. %% @private --spec terminate(_, _) -> ok. terminate(_Reason, _State) -> ok. %% @private --spec code_change(_, State, _) -> {ok, State}. code_change(_OldVsn, State, _Extra) -> {ok, State}. diff --git a/src/ranch_listener_sup.erl b/src/ranch_listener_sup.erl index c33194f..63e3ffe 100644 --- a/src/ranch_listener_sup.erl +++ b/src/ranch_listener_sup.erl @@ -16,8 +16,11 @@ -module(ranch_listener_sup). -behaviour(supervisor). --export([start_link/5]). %% API. --export([init/1]). %% supervisor. +%% API. +-export([start_link/5]). + +%% supervisor. +-export([init/1]). %% API. @@ -41,6 +44,5 @@ start_link(NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts) -> %% supervisor. --spec init([]) -> {ok, {{one_for_all, 10, 10}, []}}. init([]) -> {ok, {{one_for_all, 10, 10}, []}}. diff --git a/src/ranch_ssl.erl b/src/ranch_ssl.erl index 10cba53..51ea128 100644 --- a/src/ranch_ssl.erl +++ b/src/ranch_ssl.erl @@ -23,8 +23,19 @@ %% %% @see ssl -module(ranch_ssl). --export([name/0, messages/0, listen/1, accept/2, recv/3, send/2, setopts/2, - controlling_process/2, peername/1, close/1, sockname/1]). + +-export([name/0]). +-export([messages/0]). +-export([connect/3]). +-export([listen/1]). +-export([accept/2]). +-export([recv/3]). +-export([send/2]). +-export([setopts/2]). +-export([controlling_process/2]). +-export([peername/1]). +-export([close/1]). +-export([sockname/1]). %% @doc Name of this transport API, <em>ssl</em>. -spec name() -> ssl. @@ -37,6 +48,14 @@ name() -> ssl. -spec messages() -> {ssl, ssl_closed, ssl_error}. messages() -> {ssl, ssl_closed, ssl_error}. +%% @private +%% @todo Probably filter Opts? +-spec connect(string(), inet:port_number(), any()) + -> {ok, inet:socket()} | {error, atom()}. +connect(Host, Port, Opts) when is_list(Host), is_integer(Port) -> + ssl:connect(Host, Port, + Opts ++ [binary, {active, false}, {packet, raw}]). + %% @doc Setup a socket to listen on the given port on the local host. %% %% The available options are: diff --git a/src/ranch_sup.erl b/src/ranch_sup.erl index 942522d..5551f12 100644 --- a/src/ranch_sup.erl +++ b/src/ranch_sup.erl @@ -16,8 +16,11 @@ -module(ranch_sup). -behaviour(supervisor). --export([start_link/0]). %% API. --export([init/1]). %% supervisor. +%% API. +-export([start_link/0]). + +%% supervisor. +-export([init/1]). -define(SUPERVISOR, ?MODULE). @@ -29,12 +32,5 @@ start_link() -> %% supervisor. --spec init([]) -> {'ok', {{'one_for_one', 10, 10}, [{ - any(), {atom() | tuple(), atom(), 'undefined' | [any()]}, - 'permanent' | 'temporary' | 'transient', - 'brutal_kill' | 'infinity' | non_neg_integer(), - 'supervisor' | 'worker', - 'dynamic' | [atom() | tuple()]}] -}}. init([]) -> {ok, {{one_for_one, 10, 10}, []}}. diff --git a/src/ranch_tcp.erl b/src/ranch_tcp.erl index 5c2a61d..765da74 100644 --- a/src/ranch_tcp.erl +++ b/src/ranch_tcp.erl @@ -19,8 +19,18 @@ %% @see gen_tcp -module(ranch_tcp). --export([name/0, messages/0, listen/1, accept/2, recv/3, send/2, setopts/2, - controlling_process/2, peername/1, close/1, sockname/1]). +-export([name/0]). +-export([messages/0]). +-export([connect/3]). +-export([listen/1]). +-export([accept/2]). +-export([recv/3]). +-export([send/2]). +-export([setopts/2]). +-export([controlling_process/2]). +-export([peername/1]). +-export([close/1]). +-export([sockname/1]). %% @doc Name of this transport API, <em>tcp</em>. -spec name() -> tcp. @@ -33,6 +43,13 @@ name() -> tcp. -spec messages() -> {tcp, tcp_closed, tcp_error}. messages() -> {tcp, tcp_closed, tcp_error}. +%% @private +-spec connect(string(), inet:port_number(), any()) + -> {ok, inet:socket()} | {error, atom()}. +connect(Host, Port, Opts) when is_list(Host), is_integer(Port) -> + gen_tcp:connect(Host, Port, + Opts ++ [binary, {active, false}, {packet, raw}]). + %% @doc Setup a socket to listen on the given port on the local host. %% %% The available options are: |