aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-05-31 14:11:38 +0200
committerLoïc Hoguin <[email protected]>2017-05-31 14:11:38 +0200
commit2730f7188738cc7b1100e50bcc8567d33ecb3934 (patch)
tree66d1daac50363684954316dc6b371a51188ce6f8
parenta004ad710eddd0c21aaccc30d5633a76b06164b5 (diff)
downloadranch-2730f7188738cc7b1100e50bcc8567d33ecb3934.tar.gz
ranch-2730f7188738cc7b1100e50bcc8567d33ecb3934.tar.bz2
ranch-2730f7188738cc7b1100e50bcc8567d33ecb3934.zip
Deprecated ranch:start_listener/6 and child_spec/6
The NumAcceptors argument has been moved to transport option num_acceptor, which defaults to 10. The functions now take one less argument. The old functions are still here, though deprecated.
-rw-r--r--doc/src/guide/embedded.asciidoc2
-rw-r--r--doc/src/guide/internals.asciidoc2
-rw-r--r--doc/src/guide/listeners.asciidoc32
-rw-r--r--doc/src/guide/protocols.asciidoc2
-rw-r--r--doc/src/guide/ssl_auth.asciidoc2
-rw-r--r--doc/src/manual/ranch.asciidoc3
-rw-r--r--examples/tcp_echo/src/tcp_echo_app.erl2
-rw-r--r--examples/tcp_reverse/src/tcp_reverse_app.erl2
-rw-r--r--src/ranch.erl17
-rw-r--r--src/ranch_acceptors_sup.erl3
-rw-r--r--test/acceptor_SUITE.erl93
-rw-r--r--test/shutdown_SUITE.erl10
12 files changed, 107 insertions, 63 deletions
diff --git a/doc/src/guide/embedded.asciidoc b/doc/src/guide/embedded.asciidoc
index 593a807..55c018b 100644
--- a/doc/src/guide/embedded.asciidoc
+++ b/doc/src/guide/embedded.asciidoc
@@ -17,7 +17,7 @@ regardless of the number of listeners you will use. Then you need to
add the child specs for each listener.
Ranch has a convenience function for getting the listeners child specs
-called `ranch:child_spec/6`, that works like `ranch:start_listener/6`,
+called `ranch:child_spec/5`, that works like `ranch:start_listener/5`,
except that it doesn't start anything, it only returns child specs.
As for `ranch_sup`, the child spec is simple enough to not require a
diff --git a/doc/src/guide/internals.asciidoc b/doc/src/guide/internals.asciidoc
index fa63f1d..c5bde58 100644
--- a/doc/src/guide/internals.asciidoc
+++ b/doc/src/guide/internals.asciidoc
@@ -47,7 +47,7 @@ that new process.
=== Number of acceptors
-The second argument to `ranch:start_listener/6` is the number of
+The second argument to `ranch:start_listener/5` is the number of
processes that will be accepting connections. Care should be taken
when choosing this number.
diff --git a/doc/src/guide/listeners.asciidoc b/doc/src/guide/listeners.asciidoc
index 1055b80..97afa22 100644
--- a/doc/src/guide/listeners.asciidoc
+++ b/doc/src/guide/listeners.asciidoc
@@ -26,7 +26,7 @@ When starting a listener, a number of different settings are required:
Ranch includes both TCP and SSL transport handlers, respectively
`ranch_tcp` and `ranch_ssl`.
-A listener can be started by calling the `ranch:start_listener/6`
+A listener can be started by calling the `ranch:start_listener/5`
function. Before doing so however, you must ensure that the `ranch`
application is started.
@@ -42,7 +42,7 @@ to the `echo_protocol` handler.
.Starting a listener for TCP connections on port 5555
[source,erlang]
-{ok, _} = ranch:start_listener(tcp_echo, 100,
+{ok, _} = ranch:start_listener(tcp_echo,
ranch_tcp, [{port, 5555}],
echo_protocol, []
).
@@ -108,12 +108,12 @@ the port number 0, or if you omit the port number entirely, Ranch will
start listening on a random port.
You can retrieve this port number by calling `ranch:get_port/1`. The
-argument is the name of the listener you gave in `ranch:start_listener/6`.
+argument is the name of the listener you gave in `ranch:start_listener/5`.
.Starting a listener for TCP connections on a random port
[source,erlang]
-{ok, _} = ranch:start_listener(tcp_echo, 100,
+{ok, _} = ranch:start_listener(tcp_echo,
ranch_tcp, [{port, 0}],
echo_protocol, []
).
@@ -159,7 +159,7 @@ connections are handled optimally.
.Customizing the maximum number of concurrent connections
[source,erlang]
-{ok, _} = ranch:start_listener(tcp_echo, 100,
+{ok, _} = ranch:start_listener(tcp_echo,
ranch_tcp, [{port, 5555}, {max_connections, 100}],
echo_protocol, []
).
@@ -169,7 +169,7 @@ You can disable this limit by setting its value to the atom `infinity`.
.Disabling the limit for the number of connections
[source,erlang]
-{ok, _} = ranch:start_listener(tcp_echo, 100,
+{ok, _} = ranch:start_listener(tcp_echo,
ranch_tcp, [{port, 5555}, {max_connections, infinity}],
echo_protocol, []
).
@@ -213,6 +213,24 @@ ranch:set_max_connections(tcp_echo, MaxConns).
The change will occur immediately.
+=== Customizing the number of acceptor processes
+
+By default Ranch will use 10 acceptor processes. Their role is
+to accept connections and spawn a connection process for every
+new connection.
+
+This number can be tweaked to improve performance. A good
+number is typically between 10 or 100 acceptors. You must
+measure to find the best value for your application.
+
+.Specifying a custom number of acceptor processes
+
+[source,erlang]
+{ok, _} = ranch:start_listener(tcp_echo,
+ ranch_tcp, [{port, 5555}, {num_acceptors, 42}],
+ echo_protocol, []
+).
+
=== When running out of file descriptors
Operating systems have limits on the number of sockets
@@ -278,7 +296,7 @@ calling `ranch:get_protocol_options/1`.
[source,erlang]
Opts = ranch:get_protocol_options(tcp_echo).
-=== Obtain information about listeners
+=== Obtaining information about listeners
Ranch provides two functions for retrieving information about the
listeners, for reporting and diagnostic purposes.
diff --git a/doc/src/guide/protocols.asciidoc b/doc/src/guide/protocols.asciidoc
index 48c74ef..b9a31f2 100644
--- a/doc/src/guide/protocols.asciidoc
+++ b/doc/src/guide/protocols.asciidoc
@@ -10,7 +10,7 @@ which defines a single callback, `start_link/4`. This callback is
responsible for spawning a new process for handling the connection.
It receives four arguments: the name of the listener, the socket, the
transport handler being used and the protocol options defined in
-the call to `ranch:start_listener/6`. This callback must
+the call to `ranch:start_listener/5`. This callback must
return `{ok, Pid}`, with `Pid` the pid of the new process.
The newly started process can then freely initialize itself. However,
diff --git a/doc/src/guide/ssl_auth.asciidoc b/doc/src/guide/ssl_auth.asciidoc
index de0bbaf..de16107 100644
--- a/doc/src/guide/ssl_auth.asciidoc
+++ b/doc/src/guide/ssl_auth.asciidoc
@@ -49,7 +49,7 @@ the listener to enable this behavior.
.Configure a listener for SSL authentication
[source,erlang]
-{ok, _} = ranch:start_listener(my_ssl, 100,
+{ok, _} = ranch:start_listener(my_ssl,
ranch_ssl, [
{port, SSLPort},
{certfile, PathToCertfile},
diff --git a/doc/src/manual/ranch.asciidoc b/doc/src/manual/ranch.asciidoc
index 13380fd..e0244c8 100644
--- a/doc/src/manual/ranch.asciidoc
+++ b/doc/src/manual/ranch.asciidoc
@@ -28,6 +28,7 @@ code.
opt() = {ack_timeout, timeout()}
| {connection_type, worker | supervisor}
| {max_connections, max_conns()}
+ | {num_acceptors, pos_integer()}
| {shutdown, timeout() | brutal_kill}
| {socket, any()}
----
@@ -51,6 +52,8 @@ connection_type (worker)::
Type of process that will handle the connection.
max_connections (1024)::
Maximum number of active connections. Soft limit. Using `infinity` will disable the limit entirely.
+num_acceptors (10)::
+ Number of processes that accept connections.
shutdown (5000)::
Maximum allowed time for children to stop on listener shutdown.
socket::
diff --git a/examples/tcp_echo/src/tcp_echo_app.erl b/examples/tcp_echo/src/tcp_echo_app.erl
index 7fac685..63cbbb4 100644
--- a/examples/tcp_echo/src/tcp_echo_app.erl
+++ b/examples/tcp_echo/src/tcp_echo_app.erl
@@ -11,7 +11,7 @@
%% API.
start(_Type, _Args) ->
- {ok, _} = ranch:start_listener(tcp_echo, 1,
+ {ok, _} = ranch:start_listener(tcp_echo,
ranch_tcp, [{port, 5555}], echo_protocol, []),
tcp_echo_sup:start_link().
diff --git a/examples/tcp_reverse/src/tcp_reverse_app.erl b/examples/tcp_reverse/src/tcp_reverse_app.erl
index 106e527..1138d4a 100644
--- a/examples/tcp_reverse/src/tcp_reverse_app.erl
+++ b/examples/tcp_reverse/src/tcp_reverse_app.erl
@@ -11,7 +11,7 @@
%% API.
start(_Type, _Args) ->
- {ok, _} = ranch:start_listener(tcp_reverse, 10,
+ {ok, _} = ranch:start_listener(tcp_reverse,
ranch_tcp, [{port, 5555}], reverse_protocol, []),
tcp_reverse_sup:start_link().
diff --git a/src/ranch.erl b/src/ranch.erl
index 2ef6222..e835ad5 100644
--- a/src/ranch.erl
+++ b/src/ranch.erl
@@ -14,8 +14,10 @@
-module(ranch).
+-export([start_listener/5]).
-export([start_listener/6]).
-export([stop_listener/1]).
+-export([child_spec/5]).
-export([child_spec/6]).
-export([accept_ack/1]).
-export([remove_connection/1]).
@@ -31,12 +33,15 @@
-export([set_option_default/3]).
-export([require/1]).
+-deprecated([start_listener/6, child_spec/6]).
+
-type max_conns() :: non_neg_integer() | infinity.
-export_type([max_conns/0]).
-type opt() :: {ack_timeout, timeout()}
| {connection_type, worker | supervisor}
| {max_connections, max_conns()}
+ | {num_acceptors, pos_integer()}
| {shutdown, timeout() | brutal_kill}
| {socket, any()}.
-export_type([opt/0]).
@@ -44,6 +49,12 @@
-type ref() :: any().
-export_type([ref/0]).
+-spec start_listener(ref(), module(), any(), module(), any())
+ -> supervisor:startchild_ret().
+start_listener(Ref, Transport, TransOpts, Protocol, ProtoOpts) ->
+ NumAcceptors = proplists:get_value(num_acceptors, TransOpts, 10),
+ start_listener(Ref, NumAcceptors, Transport, TransOpts, Protocol, ProtoOpts).
+
-spec start_listener(ref(), non_neg_integer(), module(), any(), module(), any())
-> supervisor:startchild_ret().
start_listener(Ref, NumAcceptors, Transport, TransOpts, Protocol, ProtoOpts)
@@ -99,6 +110,12 @@ stop_listener(Ref) ->
{error, Reason}
end.
+-spec child_spec(ref(), module(), any(), module(), any())
+ -> supervisor:child_spec().
+child_spec(Ref, Transport, TransOpts, Protocol, ProtoOpts) ->
+ NumAcceptors = proplists:get_value(num_acceptors, TransOpts, 10),
+ child_spec(Ref, NumAcceptors, Transport, TransOpts, Protocol, ProtoOpts).
+
-spec child_spec(ref(), non_neg_integer(), module(), any(), module(), any())
-> supervisor:child_spec().
child_spec(Ref, NumAcceptors, Transport, TransOpts, Protocol, ProtoOpts)
diff --git a/src/ranch_acceptors_sup.erl b/src/ranch_acceptors_sup.erl
index 24cce2b..7092ab8 100644
--- a/src/ranch_acceptors_sup.erl
+++ b/src/ranch_acceptors_sup.erl
@@ -30,8 +30,9 @@ init([Ref, NumAcceptors, Transport, TransOpts]) ->
TransOpts2 = proplists:delete(ack_timeout,
proplists:delete(connection_type,
proplists:delete(max_connections,
+ proplists:delete(num_acceptors,
proplists:delete(shutdown,
- proplists:delete(socket, TransOpts))))),
+ proplists:delete(socket, TransOpts)))))),
case Transport:listen(TransOpts2) of
{ok, Socket} -> Socket;
{error, Reason} -> listen_error(Ref, Transport, TransOpts2, Reason)
diff --git a/test/acceptor_SUITE.erl b/test/acceptor_SUITE.erl
index 878caee..b771857 100644
--- a/test/acceptor_SUITE.erl
+++ b/test/acceptor_SUITE.erl
@@ -67,28 +67,31 @@ groups() ->
misc_bad_transport(_) ->
doc("Reject invalid transport modules."),
- {error, badarg} = ranch:start_listener(misc_bad_transport, 1,
+ {error, badarg} = ranch:start_listener(misc_bad_transport,
bad_transport, [], echo_protocol, []),
ok.
misc_bad_transport_options(_) ->
doc("Ignore invalid transport options."),
- {ok, _} = ranch:start_listener(misc_bad_transport, 1,
+ {ok, _} = ranch:start_listener(misc_bad_transport,
ranch_tcp, [binary, {packet, 4}, <<"garbage">>, raw, backlog], echo_protocol, []),
ok.
misc_info(_) ->
doc("Information about listeners."),
%% Open a listener with a few connections.
- {ok, Pid1} = ranch:start_listener({misc_info, tcp}, 1, ranch_tcp, [],
+ {ok, Pid1} = ranch:start_listener({misc_info, tcp},
+ ranch_tcp, [{num_acceptors, 1}],
remove_conn_and_wait_protocol, [{remove, true, 2500}]),
Port1 = ranch:get_port({misc_info, tcp}),
%% Open a few more listeners with different arguments.
- {ok, Pid2} = ranch:start_listener({misc_info, act}, 2, ranch_tcp, [], active_echo_protocol, {}),
+ {ok, Pid2} = ranch:start_listener({misc_info, act},
+ ranch_tcp, [{num_acceptors, 2}], active_echo_protocol, {}),
Port2 = ranch:get_port({misc_info, act}),
ranch:set_max_connections({misc_info, act}, infinity),
Opts = ct_helper:get_certs_from_ets(),
- {ok, Pid3} = ranch:start_listener({misc_info, ssl}, 3, ranch_ssl, Opts, echo_protocol, [{}]),
+ {ok, Pid3} = ranch:start_listener({misc_info, ssl},
+ ranch_ssl, [{num_acceptors, 3}|Opts], echo_protocol, [{}]),
Port3 = ranch:get_port({misc_info, ssl}),
%% Open 5 connections, 3 removed from the count.
{ok, _} = gen_tcp:connect("localhost", Port1, [binary, {active, false}, {packet, raw}]),
@@ -111,7 +114,7 @@ misc_info(_) ->
{active_connections, 0},
{all_connections, 0},
{transport, ranch_tcp},
- {transport_options, []},
+ {transport_options, [{num_acceptors, 2}]},
{protocol, active_echo_protocol},
{protocol_options, {}}
]},
@@ -124,7 +127,7 @@ misc_info(_) ->
{active_connections, 0},
{all_connections, 0},
{transport, ranch_ssl},
- {transport_options, Opts},
+ {transport_options, [{num_acceptors, 3}|Opts]},
{protocol, echo_protocol},
{protocol_options, [{}]}
]},
@@ -137,7 +140,7 @@ misc_info(_) ->
{active_connections, 2},
{all_connections, 5},
{transport, ranch_tcp},
- {transport_options, []},
+ {transport_options, [{num_acceptors, 1}]},
{protocol, remove_conn_and_wait_protocol},
{protocol_options, [{remove, false, 2500}]} %% Option was modified.
]}
@@ -158,7 +161,8 @@ ssl_accept_error(_) ->
doc("Acceptor must not crash if client disconnects in the middle of SSL handshake."),
Name = name(),
Opts = ct_helper:get_certs_from_ets(),
- {ok, ListenerSup} = ranch:start_listener(Name, 1, ranch_ssl, Opts, echo_protocol, []),
+ {ok, ListenerSup} = ranch:start_listener(Name,
+ ranch_ssl, [{num_acceptors, 1}|Opts], echo_protocol, []),
Port = ranch:get_port(Name),
ListenerSupChildren = supervisor:which_children(ListenerSup),
{_, AcceptorsSup, _, _} = lists:keyfind(ranch_acceptors_sup, 1, ListenerSupChildren),
@@ -175,7 +179,7 @@ ssl_accept_socket(_) ->
Name = name(),
Opts = ct_helper:get_certs_from_ets(),
{ok, S} = ssl:listen(0, [binary, {active, false}, {packet, raw}, {reuseaddr, true}|Opts]),
- {ok, _} = ranch:start_listener(Name, 1, ranch_ssl, [{socket, S}], echo_protocol, []),
+ {ok, _} = ranch:start_listener(Name, ranch_ssl, [{socket, S}], echo_protocol, []),
Port = ranch:get_port(Name),
{ok, Socket} = ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]),
ok = ssl:send(Socket, <<"TCP Ranch is working!">>),
@@ -190,7 +194,7 @@ ssl_active_echo(_) ->
doc("Ensure that active mode works with SSL transport."),
Name = name(),
Opts = ct_helper:get_certs_from_ets(),
- {ok, _} = ranch:start_listener(Name, 1, ranch_ssl, Opts, active_echo_protocol, []),
+ {ok, _} = ranch:start_listener(Name, ranch_ssl, Opts, active_echo_protocol, []),
Port = ranch:get_port(Name),
{ok, Socket} = ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]),
ok = ssl:send(Socket, <<"SSL Ranch is working!">>),
@@ -205,7 +209,7 @@ ssl_echo(_) ->
doc("Ensure that passive mode works with SSL transport."),
Name = name(),
Opts = ct_helper:get_certs_from_ets(),
- {ok, _} = ranch:start_listener(Name, 1, ranch_ssl, Opts, echo_protocol, []),
+ {ok, _} = ranch:start_listener(Name, ranch_ssl, Opts, echo_protocol, []),
Port = ranch:get_port(Name),
{ok, Socket} = ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]),
ok = ssl:send(Socket, <<"SSL Ranch is working!">>),
@@ -228,7 +232,7 @@ do_ssl_sni_echo() ->
doc("Ensure that SNI works with SSL transport."),
Name = name(),
Opts = ct_helper:get_certs_from_ets(),
- {ok, _} = ranch:start_listener(Name, 1, ranch_ssl, [{sni_hosts, [{"localhost", Opts}]}], echo_protocol, []),
+ {ok, _} = ranch:start_listener(Name, ranch_ssl, [{sni_hosts, [{"localhost", Opts}]}], echo_protocol, []),
Port = ranch:get_port(Name),
{ok, Socket} = ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]),
ok = ssl:send(Socket, <<"SSL Ranch is working!">>),
@@ -251,7 +255,7 @@ do_ssl_sni_fail() ->
doc("Ensure that connection fails when host is not in SNI list."),
Name = name(),
Opts = ct_helper:get_certs_from_ets(),
- {ok, _} = ranch:start_listener(Name, 1, ranch_ssl, [{sni_hosts, [{"pouet", Opts}]}], echo_protocol, []),
+ {ok, _} = ranch:start_listener(Name, ranch_ssl, [{sni_hosts, [{"pouet", Opts}]}], echo_protocol, []),
Port = ranch:get_port(Name),
{error, _} = ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]),
ok = ranch:stop_listener(Name),
@@ -263,9 +267,9 @@ ssl_error_eaddrinuse(_) ->
doc("Ensure that failure due to an eaddrinuse returns a compact readable error."),
Name = name(),
Opts = ct_helper:get_certs_from_ets(),
- {ok, _} = ranch:start_listener(Name, 1, ranch_ssl, Opts, active_echo_protocol, []),
+ {ok, _} = ranch:start_listener(Name, ranch_ssl, Opts, active_echo_protocol, []),
Port = ranch:get_port(Name),
- {error, eaddrinuse} = ranch:start_listener({Name, fails}, 1,
+ {error, eaddrinuse} = ranch:start_listener({Name, fails},
ranch_ssl, [{port, Port}|Opts], active_echo_protocol, []),
ok = ranch:stop_listener(Name),
%% Make sure the listener stopped.
@@ -274,14 +278,14 @@ ssl_error_eaddrinuse(_) ->
ssl_error_no_cert(_) ->
doc("Ensure that failure due to missing certificate returns a compact readable error."),
- {error, no_cert} = ranch:start_listener(name(), 1, ranch_ssl, [], active_echo_protocol, []),
+ {error, no_cert} = ranch:start_listener(name(), ranch_ssl, [], active_echo_protocol, []),
ok.
ssl_error_eacces(_) ->
doc("Ensure that failure due to an eacces returns a compact readable error."),
Name = name(),
Opts = ct_helper:get_certs_from_ets(),
- {error, eacces} = ranch:start_listener(Name, 1,
+ {error, eacces} = ranch:start_listener(Name,
ranch_ssl, [{port, 283}|Opts], active_echo_protocol, []),
ok.
@@ -291,7 +295,7 @@ tcp_accept_socket(_) ->
doc("Ensure that listener can use an externally opened TCP listen socket."),
Name = name(),
{ok, S} = gen_tcp:listen(0, [binary, {active, false}, {packet, raw}, {reuseaddr, true}]),
- {ok, _} = ranch:start_listener(Name, 1, ranch_tcp, [{socket, S}], echo_protocol, []),
+ {ok, _} = ranch:start_listener(Name, ranch_tcp, [{socket, S}], echo_protocol, []),
Port = ranch:get_port(Name),
{ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]),
ok = gen_tcp:send(Socket, <<"TCP Ranch is working!">>),
@@ -305,7 +309,7 @@ tcp_accept_socket(_) ->
tcp_active_echo(_) ->
doc("Ensure that active mode works with TCP transport."),
Name = name(),
- {ok, _} = ranch:start_listener(Name, 1, ranch_tcp, [], active_echo_protocol, []),
+ {ok, _} = ranch:start_listener(Name, ranch_tcp, [], active_echo_protocol, []),
Port = ranch:get_port(Name),
{ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]),
ok = gen_tcp:send(Socket, <<"TCP Ranch is working!">>),
@@ -319,7 +323,7 @@ tcp_active_echo(_) ->
tcp_echo(_) ->
doc("Ensure that passive mode works with TCP transport."),
Name = name(),
- {ok, _} = ranch:start_listener(Name, 1, ranch_tcp, [], echo_protocol, []),
+ {ok, _} = ranch:start_listener(Name, ranch_tcp, [], echo_protocol, []),
Port = ranch:get_port(Name),
{ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]),
ok = gen_tcp:send(Socket, <<"TCP Ranch is working!">>),
@@ -334,7 +338,7 @@ tcp_inherit_options(_) ->
doc("Ensure TCP options are inherited in the protocol."),
Name = name(),
Opts = [{nodelay, false}, {send_timeout_close, false}],
- {ok, _} = ranch:start_listener(Name, 4, ranch_tcp, Opts, check_tcp_options, [{pid, self()} | Opts]),
+ {ok, _} = ranch:start_listener(Name, ranch_tcp, Opts, check_tcp_options, [{pid, self()} | Opts]),
Port = ranch:get_port(Name),
{ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, true}, {packet, raw}]),
receive checked -> ok after 1000 -> error(timeout) end,
@@ -344,8 +348,8 @@ tcp_inherit_options(_) ->
tcp_max_connections(_) ->
doc("Ensure the max_connections option actually limits connections."),
Name = name(),
- {ok, _} = ranch:start_listener(Name, 1,
- ranch_tcp, [{max_connections, 10}],
+ {ok, _} = ranch:start_listener(Name,
+ ranch_tcp, [{max_connections, 10}, {num_acceptors, 1}],
notify_and_wait_protocol, [{msg, connected}, {pid, self()}]),
Port = ranch:get_port(Name),
ok = connect_loop(Port, 11, 150),
@@ -357,8 +361,8 @@ tcp_max_connections(_) ->
tcp_max_connections_and_beyond(_) ->
doc("Ensure the max_connections option works when connections are removed from the count."),
Name = name(),
- {ok, _} = ranch:start_listener(Name, 1,
- ranch_tcp, [{max_connections, 10}],
+ {ok, _} = ranch:start_listener(Name,
+ ranch_tcp, [{max_connections, 10}, {num_acceptors, 1}],
remove_conn_and_wait_protocol, [{remove, true, 2500}]),
Port = ranch:get_port(Name),
ok = connect_loop(Port, 10, 0),
@@ -384,8 +388,8 @@ tcp_max_connections_and_beyond(_) ->
tcp_max_connections_infinity(_) ->
doc("Set the max_connections option from 10 to infinity and back to 10."),
Name = name(),
- {ok, _} = ranch:start_listener(Name, 1,
- ranch_tcp, [{max_connections, 10}],
+ {ok, _} = ranch:start_listener(Name,
+ ranch_tcp, [{max_connections, 10}, {num_acceptors, 1}],
notify_and_wait_protocol, [{msg, connected}, {pid, self()}]),
Port = ranch:get_port(Name),
ok = connect_loop(Port, 20, 0),
@@ -405,7 +409,7 @@ tcp_max_connections_infinity(_) ->
tcp_remove_connections(_) ->
doc("Ensure that removed connections are only removed once."),
Name = name(),
- {ok, _} = ranch:start_listener(Name, 1,
+ {ok, _} = ranch:start_listener(Name,
ranch_tcp, [],
remove_conn_and_wait_protocol, [{remove, true, 0}]),
Port = ranch:get_port(Name),
@@ -417,8 +421,8 @@ tcp_remove_connections(_) ->
tcp_set_max_connections(_) ->
doc("Ensure that changing the max_connections option to a larger value allows for more connections."),
Name = name(),
- {ok, _} = ranch:start_listener(Name, 1,
- ranch_tcp, [{max_connections, 10}],
+ {ok, _} = ranch:start_listener(Name,
+ ranch_tcp, [{max_connections, 10}, {num_acceptors, 1}],
notify_and_wait_protocol, [{msg, connected}, {pid, self()}]),
Port = ranch:get_port(Name),
ok = connect_loop(Port, 20, 0),
@@ -433,7 +437,7 @@ tcp_set_max_connections(_) ->
tcp_set_max_connections_clean(_) ->
doc("Ensure that setting max_connections does not crash any process."),
Name = name(),
- {ok, ListSupPid} = ranch:start_listener(Name, 4, ranch_tcp,
+ {ok, ListSupPid} = ranch:start_listener(Name, ranch_tcp,
[{max_connections, 4}],
notify_and_wait_protocol, [{msg, connected}, {pid, self()}]),
Children = supervisor:which_children(ListSupPid),
@@ -459,7 +463,7 @@ tcp_set_max_connections_clean(_) ->
tcp_upgrade(_) ->
doc("Ensure that protocol options can be updated."),
Name = name(),
- {ok, _} = ranch:start_listener(Name, 1,
+ {ok, _} = ranch:start_listener(Name,
ranch_tcp, [],
notify_and_wait_protocol, [{msg, connected}, {pid, self()}]),
Port = ranch:get_port(Name),
@@ -473,9 +477,9 @@ tcp_upgrade(_) ->
tcp_error_eaddrinuse(_) ->
doc("Ensure that failure due to an eaddrinuse returns a compact readable error."),
Name = name(),
- {ok, _} = ranch:start_listener(Name, 1, ranch_tcp, [], active_echo_protocol, []),
+ {ok, _} = ranch:start_listener(Name, ranch_tcp, [], active_echo_protocol, []),
Port = ranch:get_port(Name),
- {error, eaddrinuse} = ranch:start_listener({Name, fails}, 1,
+ {error, eaddrinuse} = ranch:start_listener({Name, fails},
ranch_tcp, [{port, Port}], active_echo_protocol, []),
ok = ranch:stop_listener(Name),
%% Make sure the listener stopped.
@@ -485,7 +489,7 @@ tcp_error_eaddrinuse(_) ->
tcp_error_eacces(_) ->
doc("Ensure that failure due to an eacces returns a compact readable error."),
Name = name(),
- {error, eacces} = ranch:start_listener(Name, 1,
+ {error, eacces} = ranch:start_listener(Name,
ranch_tcp, [{port, 283}], active_echo_protocol, []),
ok.
@@ -495,7 +499,7 @@ tcp_error_eacces(_) ->
connection_type_supervisor(_) ->
doc("The supervisor connection type must be reflected in the specifications."),
Name = name(),
- {ok, _} = ranch:start_listener(Name, 1,
+ {ok, _} = ranch:start_listener(Name,
ranch_tcp, [{connection_type, supervisor}],
echo_protocol, []),
Port = ranch:get_port(Name),
@@ -513,7 +517,7 @@ connection_type_supervisor(_) ->
connection_type_supervisor_separate_from_connection(_) ->
doc("The supervisor connection type allows separate supervised and connection processes."),
Name = name(),
- {ok, _} = ranch:start_listener(Name, 1,
+ {ok, _} = ranch:start_listener(Name,
ranch_tcp, [{connection_type, supervisor}],
supervisor_separate, []),
Port = ranch:get_port(Name),
@@ -537,7 +541,7 @@ supervisor_clean_child_restart(_) ->
1 = erlang:trace_pattern({ranch_tcp, listen, 1},
[{'_', [], [{return_trace}]}], [global]),
{ok, Pid} = ranch:start_listener(Name,
- 1, ranch_tcp, [], echo_protocol, []),
+ ranch_tcp, [{num_acceptors, 1}], echo_protocol, []),
%% Trace supervisor spawns.
1 = erlang:trace(Pid, true, [procs, set_on_spawn]),
ConnsSup = ranch_server:get_connections_sup(Name),
@@ -573,7 +577,7 @@ supervisor_clean_conns_sup_restart(_) ->
"the ranch_server process."),
Name = name(),
{ok, _} = ranch:start_listener(Name,
- 1, ranch_tcp, [], echo_protocol, []),
+ ranch_tcp, [], echo_protocol, []),
Server = erlang:whereis(ranch_server),
ServerMonRef = erlang:monitor(process, Server),
%% Exit because Name already registered and is alive.
@@ -592,7 +596,8 @@ supervisor_clean_restart(_) ->
"and that it restarts properly."),
Name = name(),
NumAcc = 4,
- {ok, Pid} = ranch:start_listener(Name, NumAcc, ranch_tcp, [], echo_protocol, []),
+ {ok, Pid} = ranch:start_listener(Name,
+ ranch_tcp, [{num_acceptors, NumAcc}], echo_protocol, []),
%% Trace supervisor spawns.
1 = erlang:trace(Pid, true, [procs, set_on_spawn]),
ConnsSup0 = ranch_server:get_connections_sup(Name),
@@ -625,7 +630,7 @@ supervisor_conns_alive(_) ->
_ = erlang:trace(new, true, [call]),
1 = erlang:trace_pattern({ranch_tcp, listen, 1},
[{'_', [], [{return_trace}]}], [global]),
- {ok, _} = ranch:start_listener(Name, 1,
+ {ok, _} = ranch:start_listener(Name,
ranch_tcp, [],
remove_conn_and_wait_protocol, [{remove, false, 2500}]),
%% Get the listener socket
@@ -652,7 +657,7 @@ supervisor_conns_alive(_) ->
supervisor_protocol_start_link_crash(_) ->
doc("Ensure a protocol start crash does not kill all connections."),
Name = name(),
- {ok, _} = ranch:start_listener(Name, 1, ranch_tcp, [], crash_protocol, []),
+ {ok, _} = ranch:start_listener(Name, ranch_tcp, [], crash_protocol, []),
ConnsSup = ranch_server:get_connections_sup(Name),
Port = ranch:get_port(Name),
{ok, _} = gen_tcp:connect("localhost", Port, [binary, {active, true}, {packet, raw}]),
@@ -667,7 +672,7 @@ supervisor_server_recover_state(_) ->
_ = erlang:trace(new, true, [call]),
1 = erlang:trace_pattern({ranch_server, init, 1},
[{'_', [], [{return_trace}]}], [global]),
- {ok, _} = ranch:start_listener(Name, 1, ranch_tcp, [], echo_protocol, []),
+ {ok, _} = ranch:start_listener(Name, ranch_tcp, [], echo_protocol, []),
ConnsSup = ranch_server:get_connections_sup(Name),
ServerPid = erlang:whereis(ranch_server),
{monitors, Monitors} = erlang:process_info(ServerPid, monitors),
diff --git a/test/shutdown_SUITE.erl b/test/shutdown_SUITE.erl
index e62a1a9..505b86a 100644
--- a/test/shutdown_SUITE.erl
+++ b/test/shutdown_SUITE.erl
@@ -28,7 +28,7 @@ all() ->
brutal_kill(_) ->
doc("Shutdown Ranch listener with shutdown option set to brutal_kill."),
Name = name(),
- {ok, ListenerSup} = ranch:start_listener(Name, 1,
+ {ok, ListenerSup} = ranch:start_listener(Name,
ranch_tcp, [{port, 0}, {shutdown, brutal_kill}],
echo_protocol, []),
Port = ranch:get_port(Name),
@@ -48,7 +48,7 @@ brutal_kill(_) ->
infinity(_) ->
doc("Shutdown Ranch listener with shutdown option set to infinity."),
Name = name(),
- {ok, ListenerSup} = ranch:start_listener(Name, 1,
+ {ok, ListenerSup} = ranch:start_listener(Name,
ranch_tcp, [{port, 0}, {shutdown, infinity}],
echo_protocol, []),
Port = ranch:get_port(Name),
@@ -70,7 +70,7 @@ infinity_trap_exit(_) ->
"and protocol process trapping exits. The listener must not stop "
"until the protocol process terminates."),
Name = name(),
- {ok, ListenerSup} = ranch:start_listener(Name, 1,
+ {ok, ListenerSup} = ranch:start_listener(Name,
ranch_tcp, [{port, 0}, {shutdown, infinity}],
trap_exit_protocol, []),
Port = ranch:get_port(Name),
@@ -99,7 +99,7 @@ infinity_trap_exit(_) ->
timeout(_) ->
doc("Shutdown Ranch listener with shutdown option set to 500ms."),
Name = name(),
- {ok, ListenerSup} = ranch:start_listener(Name, 1,
+ {ok, ListenerSup} = ranch:start_listener(Name,
ranch_tcp, [{port, 0}, {shutdown, 500}],
echo_protocol, []),
Port = ranch:get_port(Name),
@@ -121,7 +121,7 @@ timeout_trap_exit(_) ->
"and protocol process trapping exits. The listener will only stop "
"after the 500ms timeout."),
Name = name(),
- {ok, ListenerSup} = ranch:start_listener(Name, 1,
+ {ok, ListenerSup} = ranch:start_listener(Name,
ranch_tcp, [{port, 0}, {shutdown, 500}],
trap_exit_protocol, []),
Port = ranch:get_port(Name),