From b400e34386ec0dc3f290da6c4671d7d0621d2fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 4 Jul 2018 10:57:05 +0200 Subject: Better distinguish between Ranch and socket options A map should now be used when specifying transport options that contain more than just socket options. It is still possible to pass a list of socket options directly as a convenience. The ack_timeout is renamed to handshake_timeout when specified as a map. This corresponds to the new function ranch:handshake/1,2 that will be favored in Ranch 2.0. Specifying Ranch-specific options via the proplist will no longer be possible starting from Ranch 2.0. --- doc/src/manual/ranch.asciidoc | 79 +++++++++++++---- src/ranch.erl | 124 ++++++++++++++++++++------- src/ranch_acceptors_sup.erl | 24 +++--- src/ranch_conns_sup.erl | 16 ++-- src/ranch_listener_sup.erl | 16 ++-- test/acceptor_SUITE.erl | 193 +++++++++++++++++++++++++++--------------- test/shutdown_SUITE.erl | 10 +-- 7 files changed, 312 insertions(+), 150 deletions(-) diff --git a/doc/src/manual/ranch.asciidoc b/doc/src/manual/ranch.asciidoc index 2380646..247558d 100644 --- a/doc/src/manual/ranch.asciidoc +++ b/doc/src/manual/ranch.asciidoc @@ -26,17 +26,43 @@ code. [source,erlang] ---- opt() = {ack_timeout, timeout()} - | {connection_type, worker | supervisor} - | {max_connections, max_conns()} - | {num_acceptors, pos_integer()} - | {shutdown, timeout() | brutal_kill} - | {socket, any()} + | {connection_type, worker | supervisor} + | {max_connections, max_conns()} + | {num_acceptors, pos_integer()} + | {shutdown, timeout() | brutal_kill} + | {socket, any()} ---- -Ranch-specific transport options. +Deprecated form for Ranch-specific options. -These options are not passed on to the transports. -They are used by Ranch while setting up the listeners. +Please use the `opts()` type when you need to provide +Ranch-specific transport options. Socket options will +remain separate from the Ranch-specific options. + +=== opts() + +[source,erlang] +---- +opts() = any() | #{ + connection_type => worker | supervisor, + handshake_timeout => timeout(), + max_connections => max_conns(), + num_acceptors => pos_integer(), + shutdown => timeout() | brutal_kill, + socket => any(), + socket_opts => any() +} +---- + +Transport options. + +The transport options are a combination of Ranch-specific +options and socket options. Socket options may be given +directly (assuming they are not a map and no Ranch-specific +option needs to be given) or as part of `socket_opts`. + +The different options are described further down in this +document. === ref() = any() @@ -46,18 +72,41 @@ Unique name used to refer to a listener. None of the options are required. -ack_timeout (5000):: - Maximum allowed time for the `ranch:handshake/{1,2}` call to finish. +ack_timeout:: + +When `ack_timeout` is found in a transport options proplist, +it is converted to the `handshake_timeout` option from the +map. They are equivalent. The `ack_timeout` option will be +removed in Ranch 2.0. + connection_type (worker):: - Type of process that will handle the connection. + +Type of process that will handle the connection. + +handshake_timeout (5000):: + +Maximum allowed time for the `ranch:handshake/1,2` call to finish. + max_connections (1024):: - Maximum number of active connections. Soft limit. Using `infinity` will disable the limit entirely. + +Maximum number of active connections. Soft limit. Using `infinity` will disable the limit entirely. + num_acceptors (10):: - Number of processes that accept connections. + +Number of processes that accept connections. + shutdown (5000):: - Maximum allowed time for children to stop on listener shutdown. + +Maximum allowed time for children to stop on listener shutdown. + socket:: - Listening socket opened externally to be used instead of calling `Transport:listen/1`. + +Listening socket opened externally to be used instead of calling `Transport:listen/1`. + +socket_opts:: + +Socket options given to the `Transport:listen/1`. Please refer to the +documentation of the transport module you are using for more details. == Exports diff --git a/src/ranch.erl b/src/ranch.erl index 0edcd78..cab6e8f 100644 --- a/src/ranch.erl +++ b/src/ranch.erl @@ -48,6 +48,7 @@ -type max_conns() :: non_neg_integer() | infinity. -export_type([max_conns/0]). +%% This type is deprecated and will be removed in Ranch 2.0. -type opt() :: {ack_timeout, timeout()} | {connection_type, worker | supervisor} | {max_connections, max_conns()} @@ -56,28 +57,33 @@ | {socket, any()}. -export_type([opt/0]). +-type opts() :: any() | #{ + connection_type => worker | supervisor, + handshake_timeout => timeout(), + max_connections => max_conns(), + num_acceptors => pos_integer(), + shutdown => timeout() | brutal_kill, + socket => any(), + socket_opts => any() +}. +-export_type([opts/0]). + -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()) +-spec start_listener(ref(), module(), opts(), module(), any()) -> supervisor:startchild_ret(). -start_listener(Ref, NumAcceptors, Transport, TransOpts, Protocol, ProtoOpts) - when is_integer(NumAcceptors) andalso is_atom(Transport) - andalso is_atom(Protocol) -> +start_listener(Ref, Transport, TransOpts0, Protocol, ProtoOpts) + when is_atom(Transport), is_atom(Protocol) -> + TransOpts = normalize_opts(TransOpts0), _ = code:ensure_loaded(Transport), case erlang:function_exported(Transport, name, 0) of false -> {error, badarg}; true -> - Res = supervisor:start_child(ranch_sup, child_spec(Ref, NumAcceptors, + Res = supervisor:start_child(ranch_sup, child_spec(Ref, Transport, TransOpts, Protocol, ProtoOpts)), - Socket = proplists:get_value(socket, TransOpts), + Socket = maps:get(socket, TransOpts, undefined), case Res of {ok, Pid} when Socket =/= undefined -> %% Give ownership of the socket to ranch_acceptors_sup @@ -98,6 +104,59 @@ start_listener(Ref, NumAcceptors, Transport, TransOpts, Protocol, ProtoOpts) maybe_started(Res) end. +-spec start_listener(ref(), non_neg_integer(), module(), opts(), module(), any()) + -> supervisor:startchild_ret(). +start_listener(Ref, NumAcceptors, Transport, TransOpts0, Protocol, ProtoOpts) + when is_integer(NumAcceptors), is_atom(Transport), is_atom(Protocol) -> + TransOpts = normalize_opts(TransOpts0), + start_listener(Ref, Transport, TransOpts#{num_acceptors => NumAcceptors}, + Protocol, ProtoOpts). + +normalize_opts(Map) when is_map(Map) -> + Map; +normalize_opts(List0) when is_list(List0) -> + Map0 = #{}, + {Map1, List1} = case take(ack_timeout, List0) of + {value, HandshakeTimeout, Tail0} -> + {Map0#{handshake_timeout => HandshakeTimeout}, Tail0}; + false -> + {Map0, List0} + end, + {Map, List} = lists:foldl(fun(Key, {Map2, List2}) -> + case take(Key, List2) of + {value, ConnectionType, Tail2} -> + {Map2#{Key => ConnectionType}, Tail2}; + false -> + {Map2, List2} + end + end, {Map1, List1}, [connection_type, max_connections, num_acceptors, shutdown, socket]), + if + Map =:= #{} -> + ok; + true -> + %% @todo This needs a test. + error_logger:warning_msg( + "Setting Ranch options together with socket options " + "is deprecated. Please use the new map syntax that allows " + "specifying socket options separately from other options.~n") + end, + case List of + [] -> Map; + _ -> Map#{socket_opts => List} + end; +normalize_opts(Any) -> + #{socket_opts => Any}. + +take(Key, List) -> + take(Key, List, []). + +take(_, [], _) -> + false; +take(Key, [{Key, Value}|Tail], Acc) -> + {value, Value, lists:reverse(Acc, Tail)}; +take(Key, [Value|Tail], Acc) -> + take(Key, Tail, [Value|Acc]). + maybe_started({error, {{shutdown, {failed_to_start_child, ranch_acceptors_sup, {listen_error, _, Reason}}}, _}} = Error) -> @@ -151,25 +210,26 @@ maybe_resumed({ok, _, _}) -> maybe_resumed(Res) -> Res. --spec child_spec(ref(), module(), any(), module(), any()) +-spec child_spec(ref(), module(), opts(), 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) - when is_integer(NumAcceptors) andalso is_atom(Transport) - andalso is_atom(Protocol) -> +child_spec(Ref, Transport, TransOpts0, Protocol, ProtoOpts) -> + TransOpts = normalize_opts(TransOpts0), {{ranch_listener_sup, Ref}, {ranch_listener_sup, start_link, [ - Ref, NumAcceptors, Transport, TransOpts, Protocol, ProtoOpts + Ref, Transport, TransOpts, Protocol, ProtoOpts ]}, permanent, infinity, supervisor, [ranch_listener_sup]}. +-spec child_spec(ref(), non_neg_integer(), module(), opts(), module(), any()) + -> supervisor:child_spec(). +child_spec(Ref, NumAcceptors, Transport, TransOpts0, Protocol, ProtoOpts) + when is_integer(NumAcceptors), is_atom(Transport), is_atom(Protocol) -> + TransOpts = normalize_opts(TransOpts0), + child_spec(Ref, Transport, TransOpts#{num_acceptors => NumAcceptors}, + Protocol, ProtoOpts). + -spec accept_ack(ref()) -> ok. accept_ack(Ref) -> - receive {handshake, Ref, Transport, Socket, AckTimeout} -> - Transport:accept_ack(Socket, AckTimeout) + receive {handshake, Ref, Transport, Socket, HandshakeTimeout} -> + Transport:accept_ack(Socket, HandshakeTimeout) end. -spec handshake(ref()) -> {ok, ranch_transport:socket()}. @@ -178,8 +238,8 @@ handshake(Ref) -> -spec handshake(ref(), any()) -> {ok, ranch_transport:socket()}. handshake(Ref, Opts) -> - receive {handshake, Ref, Transport, Socket, AckTimeout} -> - Transport:handshake(Socket, Opts, AckTimeout) + receive {handshake, Ref, Transport, Socket, HandshakeTimeout} -> + Transport:handshake(Socket, Opts, HandshakeTimeout) end. -spec remove_connection(ref()) -> ok. @@ -220,8 +280,9 @@ set_max_connections(Ref, MaxConnections) -> get_transport_options(Ref) -> ranch_server:get_transport_options(Ref). --spec set_transport_options(ref(), any()) -> ok | {error, running}. -set_transport_options(Ref, TransOpts) -> +-spec set_transport_options(ref(), opts()) -> ok | {error, running}. +set_transport_options(Ref, TransOpts0) -> + TransOpts = normalize_opts(TransOpts0), case get_status(Ref) of suspended -> ok = ranch_server:set_transport_options(Ref, TransOpts); @@ -229,7 +290,7 @@ set_transport_options(Ref, TransOpts) -> {error, running} end. --spec get_protocol_options(ref()) -> any(). +-spec get_protocol_options(ref()) -> opts(). get_protocol_options(Ref) -> ranch_server:get_protocol_options(Ref). @@ -248,7 +309,7 @@ info(Ref) -> listener_info(Ref, Pid). listener_info(Ref, Pid) -> - [_, NumAcceptors, Transport, _, Protocol, _] = ranch_server:get_listener_start_args(Ref), + [_, Transport, _, Protocol, _] = ranch_server:get_listener_start_args(Ref), ConnsSup = ranch_server:get_connections_sup(Ref), Status = get_status(Ref), {IP, Port} = get_addr(Ref), @@ -260,7 +321,6 @@ listener_info(Ref, Pid) -> {status, Status}, {ip, IP}, {port, Port}, - {num_acceptors, NumAcceptors}, {max_connections, MaxConns}, {active_connections, ranch_conns_sup:active_connections(ConnsSup)}, {all_connections, proplists:get_value(active, supervisor:count_children(ConnsSup))}, diff --git a/src/ranch_acceptors_sup.erl b/src/ranch_acceptors_sup.erl index 9e39f2d..9ec4abf 100644 --- a/src/ranch_acceptors_sup.erl +++ b/src/ranch_acceptors_sup.erl @@ -15,28 +15,24 @@ -module(ranch_acceptors_sup). -behaviour(supervisor). --export([start_link/3]). +-export([start_link/2]). -export([init/1]). --spec start_link(ranch:ref(), non_neg_integer(), module()) +-spec start_link(ranch:ref(), module()) -> {ok, pid()}. -start_link(Ref, NumAcceptors, Transport) -> - supervisor:start_link(?MODULE, [Ref, NumAcceptors, Transport]). +start_link(Ref, Transport) -> + supervisor:start_link(?MODULE, [Ref, Transport]). -init([Ref, NumAcceptors, Transport]) -> +init([Ref, Transport]) -> ConnsSup = ranch_server:get_connections_sup(Ref), TransOpts = ranch_server:get_transport_options(Ref), - LSocket = case proplists:get_value(socket, TransOpts) of + NumAcceptors = maps:get(num_acceptors, TransOpts, 10), + LSocket = case maps:get(socket, TransOpts, undefined) of undefined -> - TransOpts2 = proplists:delete(ack_timeout, - proplists:delete(connection_type, - proplists:delete(max_connections, - proplists:delete(num_acceptors, - proplists:delete(shutdown, - proplists:delete(socket, TransOpts)))))), - case Transport:listen(TransOpts2) of + SocketOpts = maps:get(socket_opts, TransOpts, []), + case Transport:listen(SocketOpts) of {ok, Socket} -> Socket; - {error, Reason} -> listen_error(Ref, Transport, TransOpts2, Reason) + {error, Reason} -> listen_error(Ref, Transport, SocketOpts, Reason) end; Socket -> Socket diff --git a/src/ranch_conns_sup.erl b/src/ranch_conns_sup.erl index 72de2d7..ddf9a20 100644 --- a/src/ranch_conns_sup.erl +++ b/src/ranch_conns_sup.erl @@ -39,7 +39,7 @@ transport = undefined :: module(), protocol = undefined :: module(), opts :: any(), - ack_timeout :: timeout(), + handshake_timeout :: timeout(), max_conns = undefined :: ranch:max_conns() }). @@ -99,14 +99,14 @@ init(Parent, Ref, Transport, Protocol) -> ok = ranch_server:set_connections_sup(Ref, self()), MaxConns = ranch_server:get_max_connections(Ref), TransOpts = ranch_server:get_transport_options(Ref), - ConnType = proplists:get_value(connection_type, TransOpts, worker), - Shutdown = proplists:get_value(shutdown, TransOpts, 5000), - AckTimeout = proplists:get_value(ack_timeout, TransOpts, 5000), + ConnType = maps:get(connection_type, TransOpts, worker), + Shutdown = maps:get(shutdown, TransOpts, 5000), + HandshakeTimeout = maps:get(handshake_timeout, TransOpts, 5000), ProtoOpts = ranch_server:get_protocol_options(Ref), ok = proc_lib:init_ack(Parent, {ok, self()}), loop(#state{parent=Parent, ref=Ref, conn_type=ConnType, shutdown=Shutdown, transport=Transport, protocol=Protocol, - opts=ProtoOpts, ack_timeout=AckTimeout, max_conns=MaxConns}, 0, 0, []). + opts=ProtoOpts, handshake_timeout=HandshakeTimeout, max_conns=MaxConns}, 0, 0, []). loop(State=#state{parent=Parent, ref=Ref, conn_type=ConnType, transport=Transport, protocol=Protocol, opts=Opts, @@ -219,11 +219,11 @@ loop(State=#state{parent=Parent, ref=Ref, conn_type=ConnType, loop(State, CurConns, NbChildren, Sleepers) end. -handshake(State=#state{ref=Ref, transport=Transport, ack_timeout=AckTimeout, max_conns=MaxConns}, - CurConns, NbChildren, Sleepers, To, Socket, SupPid, ProtocolPid) -> +handshake(State=#state{ref=Ref, transport=Transport, handshake_timeout=HandshakeTimeout, + max_conns=MaxConns}, CurConns, NbChildren, Sleepers, To, Socket, SupPid, ProtocolPid) -> case Transport:controlling_process(Socket, ProtocolPid) of ok -> - ProtocolPid ! {handshake, Ref, Transport, Socket, AckTimeout}, + ProtocolPid ! {handshake, Ref, Transport, Socket, HandshakeTimeout}, put(SupPid, active), CurConns2 = CurConns + 1, if CurConns2 < MaxConns -> diff --git a/src/ranch_listener_sup.erl b/src/ranch_listener_sup.erl index bd4ccc5..3853425 100644 --- a/src/ranch_listener_sup.erl +++ b/src/ranch_listener_sup.erl @@ -15,27 +15,27 @@ -module(ranch_listener_sup). -behaviour(supervisor). --export([start_link/6]). +-export([start_link/5]). -export([init/1]). --spec start_link(ranch:ref(), non_neg_integer(), module(), any(), module(), any()) +-spec start_link(ranch:ref(), module(), any(), module(), any()) -> {ok, pid()}. -start_link(Ref, NumAcceptors, Transport, TransOpts, Protocol, ProtoOpts) -> - MaxConns = proplists:get_value(max_connections, TransOpts, 1024), +start_link(Ref, Transport, TransOpts, Protocol, ProtoOpts) -> + MaxConns = maps:get(max_connections, TransOpts, 1024), ranch_server:set_new_listener_opts(Ref, MaxConns, TransOpts, ProtoOpts, - [Ref, NumAcceptors, Transport, TransOpts, Protocol, ProtoOpts]), + [Ref, Transport, TransOpts, Protocol, ProtoOpts]), supervisor:start_link(?MODULE, { - Ref, NumAcceptors, Transport, Protocol + Ref, Transport, Protocol }). -init({Ref, NumAcceptors, Transport, Protocol}) -> +init({Ref, Transport, Protocol}) -> ok = ranch_server:set_listener_sup(Ref, self()), ChildSpecs = [ {ranch_conns_sup, {ranch_conns_sup, start_link, [Ref, Transport, Protocol]}, permanent, infinity, supervisor, [ranch_conns_sup]}, {ranch_acceptors_sup, {ranch_acceptors_sup, start_link, - [Ref, NumAcceptors, Transport]}, + [Ref, Transport]}, permanent, infinity, supervisor, [ranch_acceptors_sup]} ], {ok, {{rest_for_one, 1, 5}, ChildSpecs}}. diff --git a/test/acceptor_SUITE.erl b/test/acceptor_SUITE.erl index 0be5d40..50f0ce2 100644 --- a/test/acceptor_SUITE.erl +++ b/test/acceptor_SUITE.erl @@ -83,30 +83,34 @@ groups() -> misc_bad_transport(_) -> doc("Reject invalid transport modules."), {error, badarg} = ranch:start_listener(misc_bad_transport, - bad_transport, [], echo_protocol, []), + bad_transport, #{}, + echo_protocol, []), ok. misc_bad_transport_options(_) -> doc("Ignore invalid transport options."), - {ok, _} = ranch:start_listener(misc_bad_transport, - ranch_tcp, [binary, {packet, 4}, <<"garbage">>, raw, backlog], echo_protocol, []), + {ok, _} = ranch:start_listener(misc_bad_transport_options, + 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}, - ranch_tcp, [{num_acceptors, 1}], + 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}, - ranch_tcp, [{num_acceptors, 2}], active_echo_protocol, {}), + 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}, - ranch_ssl, [{num_acceptors, 3}|Opts], echo_protocol, [{}]), + ranch_ssl, #{num_acceptors => 3, socket_opts => 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}]), @@ -125,12 +129,11 @@ misc_info(_) -> {status, _}, {ip, _}, {port, Port2}, - {num_acceptors, 2}, {max_connections, infinity}, %% Option was modified. {active_connections, 0}, {all_connections, 0}, {transport, ranch_tcp}, - {transport_options, [{num_acceptors, 2}]}, + {transport_options, #{num_acceptors := 2}}, {protocol, active_echo_protocol}, {protocol_options, {}} ]}, @@ -139,12 +142,11 @@ misc_info(_) -> {status, _}, {ip, _}, {port, Port3}, - {num_acceptors, 3}, {max_connections, 1024}, {active_connections, 0}, {all_connections, 0}, {transport, ranch_ssl}, - {transport_options, [{num_acceptors, 3}|Opts]}, + {transport_options, #{num_acceptors := 3, socket_opts := Opts}}, {protocol, echo_protocol}, {protocol_options, [{}]} ]}, @@ -153,12 +155,11 @@ misc_info(_) -> {status, _}, {ip, _}, {port, Port1}, - {num_acceptors, 1}, {max_connections, 1024}, {active_connections, 2}, {all_connections, 5}, {transport, ranch_tcp}, - {transport_options, [{num_acceptors, 1}]}, + {transport_options, #{num_acceptors := 1}}, {protocol, remove_conn_and_wait_protocol}, {protocol_options, [{remove, false, 2500}]} %% Option was modified. ]} @@ -177,15 +178,20 @@ misc_info_embedded(_) -> doc("Information about listeners in embedded mode."), {ok, SupPid} = embedded_sup:start_link(), %% Open a listener with a few connections. - {ok, Pid1} = embedded_sup:start_listener(SupPid, {misc_info_embedded, tcp}, ranch_tcp, [{num_acceptors, 1}], remove_conn_and_wait_protocol, [{remove, true, 2500}]), + {ok, Pid1} = embedded_sup:start_listener(SupPid, {misc_info_embedded, tcp}, + ranch_tcp, #{num_acceptors => 1}, + remove_conn_and_wait_protocol, [{remove, true, 2500}]), Port1 = ranch:get_port({misc_info_embedded, tcp}), %% Open a few more listeners with different arguments. - {ok, Pid2} = embedded_sup:start_listener(SupPid, {misc_info_embedded, act}, ranch_tcp, [{num_acceptors, 2}], active_echo_protocol, {}), + {ok, Pid2} = embedded_sup:start_listener(SupPid, {misc_info_embedded, act}, + ranch_tcp, #{num_acceptors => 2}, + active_echo_protocol, {}), Port2 = ranch:get_port({misc_info_embedded, act}), ranch:set_max_connections({misc_info_embedded, act}, infinity), Opts = ct_helper:get_certs_from_ets(), {ok, Pid3} = embedded_sup:start_listener(SupPid, {misc_info_embedded, ssl}, - ranch_ssl, [{num_acceptors, 3}|Opts], echo_protocol, [{}]), + ranch_ssl, #{num_acceptors => 3, socket_opts => Opts}, + echo_protocol, [{}]), Port3 = ranch:get_port({misc_info_embedded, ssl}), %% Open 5 connections, 3 removed from the count. {ok, _} = gen_tcp:connect("localhost", Port1, [binary, {active, false}, {packet, raw}]), @@ -204,12 +210,11 @@ misc_info_embedded(_) -> {status, _}, {ip, _}, {port, Port2}, - {num_acceptors, 2}, {max_connections, infinity}, %% Option was modified. {active_connections, 0}, {all_connections, 0}, {transport, ranch_tcp}, - {transport_options, [{num_acceptors, 2}]}, + {transport_options, #{num_acceptors := 2}}, {protocol, active_echo_protocol}, {protocol_options, {}} ]}, @@ -218,12 +223,11 @@ misc_info_embedded(_) -> {status, _}, {ip, _}, {port, Port3}, - {num_acceptors, 3}, {max_connections, 1024}, {active_connections, 0}, {all_connections, 0}, {transport, ranch_ssl}, - {transport_options, [{num_acceptors, 3}|Opts]}, + {transport_options, #{num_acceptors := 3, socket_opts := Opts}}, {protocol, echo_protocol}, {protocol_options, [{}]} ]}, @@ -232,12 +236,11 @@ misc_info_embedded(_) -> {status, _}, {ip, _}, {port, Port1}, - {num_acceptors, 1}, {max_connections, 1024}, {active_connections, 2}, {all_connections, 5}, {transport, ranch_tcp}, - {transport_options, [{num_acceptors, 1}]}, + {transport_options, #{num_acceptors := 1}}, {protocol, remove_conn_and_wait_protocol}, {protocol_options, [{remove, false, 2500}]} %% Option was modified. ]} @@ -288,7 +291,7 @@ misc_wait_for_connections(_) -> Pid2GE = do_create_waiter(Self, Name, '>=', 2), Pid2EQ = do_create_waiter(Self, Name, '==', 2), {ok, _} = ranch:start_listener(Name, - ranch_tcp, [{num_acceptors, 1}], + ranch_tcp, #{num_acceptors => 1}, echo_protocol, []), Port = ranch:get_port(Name), %% Create some connections, ensure that waiters respond. @@ -351,7 +354,8 @@ ssl_accept_error(_) -> Name = name(), Opts = ct_helper:get_certs_from_ets(), {ok, ListenerSup} = ranch:start_listener(Name, - ranch_ssl, [{num_acceptors, 1}|Opts], echo_protocol, []), + ranch_ssl, #{num_acceptors => 1, socket_opts => Opts}, + echo_protocol, []), Port = ranch:get_port(Name), ListenerSupChildren = supervisor:which_children(ListenerSup), {_, AcceptorsSup, _, _} = lists:keyfind(ranch_acceptors_sup, 1, ListenerSupChildren), @@ -368,7 +372,9 @@ 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, 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!">>), @@ -383,7 +389,9 @@ 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, 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!">>), @@ -398,7 +406,9 @@ 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, 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!">>), @@ -421,7 +431,9 @@ 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, 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!">>), @@ -444,7 +456,9 @@ 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, 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), @@ -456,7 +470,9 @@ ssl_graceful(_) -> doc("Ensure suspending and resuming of listeners does not kill active connections."), Name = name(), Opts = ct_helper:get_certs_from_ets(), - {ok, _} = ranch:start_listener(Name, ranch_ssl, Opts, echo_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_ssl, Opts, + echo_protocol, []), Port = ranch:get_port(Name), %% Make sure connections with a fresh listener work. running = ranch:get_status(Name), @@ -465,7 +481,7 @@ ssl_graceful(_) -> ok = ssl:send(Socket1, <<"SSL with fresh listener">>), {ok, <<"SSL with fresh listener">>} = ssl:recv(Socket1, 23, 1000), %% Make sure transport options cannot be changed on a running listener. - {error, running} = ranch:set_transport_options(Name, [{port, Port}|Opts]), + {error, running} = ranch:set_transport_options(Name, #{socket_opts => [{port, Port}|Opts]}), %% Suspend listener, make sure established connections keep running. ok = ranch:suspend_listener(Name), suspended = ranch:get_status(Name), @@ -475,7 +491,7 @@ ssl_graceful(_) -> {error, econnrefused} = ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), %% Make sure transport options can be changed when listener is suspended. - ok = ranch:set_transport_options(Name, [{port, Port}|Opts]), + ok = ranch:set_transport_options(Name, #{socket_opts => [{port, Port}|Opts]}), %% Resume listener, make sure connections can be established again. ok = ranch:resume_listener(Name), running = ranch:get_status(Name), @@ -484,7 +500,7 @@ ssl_graceful(_) -> ok = ssl:send(Socket2, <<"SSL with resumed listener">>), {ok, <<"SSL with resumed listener">>} = ssl:recv(Socket2, 25, 1000), %% Make sure transport options cannot be changed on resumed listener. - {error, running} = ranch:set_transport_options(Name, [{port, Port}|Opts]), + {error, running} = ranch:set_transport_options(Name, #{socket_opts => [{port, Port}|Opts]}), ok = ranch:stop_listener(Name), {error, closed} = ssl:recv(Socket1, 0, 1000), {error, closed} = ssl:recv(Socket2, 0, 1000), @@ -495,7 +511,9 @@ ssl_accept_ack(_) -> doc("Ensure accept_ack works with SSL transport."), Name = name(), Opts = ct_helper:get_certs_from_ets(), - {ok, _} = ranch:start_listener(Name, ranch_ssl, Opts, accept_ack_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_ssl, Opts, + accept_ack_protocol, []), Port = ranch:get_port(Name), {ok, Socket} = ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok = ssl:send(Socket, <<"SSL transport accept_ack is working!">>), @@ -509,7 +527,9 @@ ssl_getopts_capability(_) -> doc("Ensure getopts/2 capability."), Name=name(), Opts=ct_helper:get_certs_from_ets(), - {ok, _}=ranch:start_listener(Name, ranch_ssl, Opts, transport_capabilities_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_ssl, Opts, + transport_capabilities_protocol, []), Port=ranch:get_port(Name), {ok, Socket}=ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok=ssl:send(Socket, <<"getopts/2">>), @@ -531,7 +551,9 @@ do_ssl_getstat_capability() -> doc("Ensure getstat/{1,2} capability."), Name=name(), Opts=ct_helper:get_certs_from_ets(), - {ok, _}=ranch:start_listener(Name, ranch_ssl, Opts, transport_capabilities_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_ssl, Opts, + transport_capabilities_protocol, []), Port=ranch:get_port(Name), {ok, Socket}=ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok=ssl:send(Socket, <<"getstat/1">>), @@ -547,10 +569,13 @@ 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, 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}, - ranch_ssl, [{port, Port}|Opts], active_echo_protocol, []), + ranch_ssl, [{port, Port}|Opts], + active_echo_protocol, []), ok = ranch:stop_listener(Name), %% Make sure the listener stopped. {'EXIT', _} = begin catch ranch:get_port(Name) end, @@ -558,7 +583,9 @@ 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(), ranch_ssl, [], active_echo_protocol, []), + {error, no_cert} = ranch:start_listener(name(), + ranch_ssl, #{}, + active_echo_protocol, []), ok. ssl_error_eacces(_) -> @@ -570,7 +597,8 @@ ssl_error_eacces(_) -> Name = name(), Opts = ct_helper:get_certs_from_ets(), {error, eacces} = ranch:start_listener(Name, - ranch_ssl, [{port, 283}|Opts], active_echo_protocol, []), + ranch_ssl, [{port, 283}|Opts], + active_echo_protocol, []), ok end. @@ -580,7 +608,9 @@ 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, 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!">>), @@ -594,7 +624,9 @@ tcp_accept_socket(_) -> tcp_active_echo(_) -> doc("Ensure that active mode works with TCP transport."), Name = name(), - {ok, _} = ranch:start_listener(Name, 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!">>), @@ -608,7 +640,9 @@ tcp_active_echo(_) -> tcp_echo(_) -> doc("Ensure that passive mode works with TCP transport."), Name = name(), - {ok, _} = ranch:start_listener(Name, 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!">>), @@ -622,7 +656,9 @@ tcp_echo(_) -> tcp_graceful(_) -> doc("Ensure suspending and resuming of listeners does not kill active connections."), Name = name(), - {ok, _} = ranch:start_listener(Name, ranch_tcp, [], echo_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_tcp, #{}, + echo_protocol, []), Port = ranch:get_port(Name), %% Make sure connections with a fresh listener work. running = ranch:get_status(Name), @@ -660,7 +696,9 @@ tcp_graceful(_) -> tcp_accept_ack(_) -> doc("Ensure accept_ack works with TCP transport."), Name = name(), - {ok, _} = ranch:start_listener(Name, ranch_tcp, [], accept_ack_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_tcp, #{}, + accept_ack_protocol, []), Port = ranch:get_port(Name), {ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok = gen_tcp:send(Socket, <<"TCP transport accept_ack is working!">>), @@ -674,7 +712,9 @@ 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, 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, @@ -685,7 +725,7 @@ tcp_max_connections(_) -> doc("Ensure the max_connections option actually limits connections."), Name = name(), {ok, _} = ranch:start_listener(Name, - ranch_tcp, [{max_connections, 10}, {num_acceptors, 1}], + 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), @@ -698,7 +738,7 @@ 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, - ranch_tcp, [{max_connections, 10}, {num_acceptors, 1}], + 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), @@ -725,7 +765,7 @@ 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, - ranch_tcp, [{max_connections, 10}, {num_acceptors, 1}], + 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), @@ -746,7 +786,7 @@ tcp_remove_connections(_) -> doc("Ensure that removed connections are only removed once."), Name = name(), {ok, _} = ranch:start_listener(Name, - ranch_tcp, [], + ranch_tcp, #{}, remove_conn_and_wait_protocol, [{remove, true, 0}]), Port = ranch:get_port(Name), ok = connect_loop(Port, 10, 0), @@ -758,7 +798,7 @@ 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, - ranch_tcp, [{max_connections, 10}, {num_acceptors, 1}], + 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), @@ -779,9 +819,9 @@ tcp_set_max_connections_clean(Config) -> do_tcp_set_max_connections_clean(_) -> doc("Ensure that setting max_connections does not crash any process."), Name = name(), - {ok, ListSupPid} = ranch:start_listener(Name, ranch_tcp, - [{max_connections, 4}], - notify_and_wait_protocol, [{msg, connected}, {pid, self()}]), + {ok, ListSupPid} = ranch:start_listener(Name, + ranch_tcp, #{max_connections => 4}, + notify_and_wait_protocol, [{msg, connected}, {pid, self()}]), Children = supervisor:which_children(ListSupPid), {_, AccSupPid, _, _} = lists:keyfind(ranch_acceptors_sup, 1, Children), 1 = erlang:trace(ListSupPid, true, [procs]), @@ -805,7 +845,9 @@ do_tcp_set_max_connections_clean(_) -> tcp_getopts_capability(_) -> doc("Ensure getopts/2 capability."), Name=name(), - {ok, _}=ranch:start_listener(Name, ranch_tcp, [], transport_capabilities_protocol, []), + {ok, _}=ranch:start_listener(Name, + ranch_tcp, #{}, + transport_capabilities_protocol, []), Port=ranch:get_port(Name), {ok, Socket}=gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok=gen_tcp:send(Socket, <<"getopts/2">>), @@ -818,7 +860,9 @@ tcp_getopts_capability(_) -> tcp_getstat_capability(_) -> doc("Ensure getstat/{1,2} capability."), Name=name(), - {ok, _}=ranch:start_listener(Name, ranch_tcp, [], transport_capabilities_protocol, []), + {ok, _}=ranch:start_listener(Name, + ranch_tcp, #{}, + transport_capabilities_protocol, []), Port=ranch:get_port(Name), {ok, Socket}=gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok=gen_tcp:send(Socket, <<"getstat/1">>), @@ -834,7 +878,7 @@ tcp_upgrade(_) -> doc("Ensure that protocol options can be updated."), Name = name(), {ok, _} = ranch:start_listener(Name, - ranch_tcp, [], + ranch_tcp, #{}, notify_and_wait_protocol, [{msg, connected}, {pid, self()}]), Port = ranch:get_port(Name), ok = connect_loop(Port, 1, 0), @@ -847,10 +891,13 @@ 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, 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}, - ranch_tcp, [{port, Port}], active_echo_protocol, []), + ranch_tcp, [{port, Port}], + active_echo_protocol, []), ok = ranch:stop_listener(Name), %% Make sure the listener stopped. {'EXIT', _} = begin catch ranch:get_port(Name) end, @@ -864,7 +911,8 @@ tcp_error_eacces(_) -> doc("Ensure that failure due to an eacces returns a compact readable error."), Name = name(), {error, eacces} = ranch:start_listener(Name, - ranch_tcp, [{port, 283}], active_echo_protocol, []), + ranch_tcp, [{port, 283}], + active_echo_protocol, []), ok end. @@ -874,7 +922,7 @@ connection_type_supervisor(_) -> doc("The supervisor connection type must be reflected in the specifications."), Name = name(), {ok, _} = ranch:start_listener(Name, - ranch_tcp, [{connection_type, supervisor}], + ranch_tcp, #{connection_type => supervisor}, echo_protocol, []), Port = ranch:get_port(Name), {ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), @@ -892,7 +940,7 @@ connection_type_supervisor_separate_from_connection(_) -> doc("The supervisor connection type allows separate supervised and connection processes."), Name = name(), {ok, _} = ranch:start_listener(Name, - ranch_tcp, [{connection_type, supervisor}], + ranch_tcp, #{connection_type => supervisor}, supervisor_separate, []), Port = ranch:get_port(Name), {ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), @@ -951,7 +999,8 @@ do_supervisor_clean_child_restart(_) -> 1 = erlang:trace_pattern({ranch_tcp, listen, 1}, [{'_', [], [{return_trace}]}], [global]), {ok, Pid} = ranch:start_listener(Name, - ranch_tcp, [{num_acceptors, 1}], 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), @@ -987,7 +1036,8 @@ supervisor_clean_conns_sup_restart(_) -> "the ranch_server process."), Name = name(), {ok, _} = ranch:start_listener(Name, - 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. @@ -1013,7 +1063,8 @@ do_supervisor_clean_restart(_) -> Name = name(), NumAcc = 4, {ok, Pid} = ranch:start_listener(Name, - ranch_tcp, [{num_acceptors, NumAcc}], echo_protocol, []), + 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), @@ -1053,7 +1104,7 @@ do_supervisor_conns_alive(_) -> 1 = erlang:trace_pattern({ranch_tcp, listen, 1}, [{'_', [], [{return_trace}]}], [global]), {ok, _} = ranch:start_listener(Name, - ranch_tcp, [], + ranch_tcp, #{}, remove_conn_and_wait_protocol, [{remove, false, 2500}]), %% Get the listener socket LSocket = receive @@ -1079,7 +1130,9 @@ do_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, 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}]), @@ -1100,7 +1153,9 @@ do_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, 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), @@ -1125,7 +1180,9 @@ supervisor_unexpected_message(_) -> doc("Ensure the connections supervisor stays alive when it receives " "an unexpected message."), Name = name(), - {ok, ListenerPid} = ranch:start_listener(Name, ranch_tcp, [], echo_protocol, []), + {ok, ListenerPid} = 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!">>), diff --git a/test/shutdown_SUITE.erl b/test/shutdown_SUITE.erl index d46e223..249458e 100644 --- a/test/shutdown_SUITE.erl +++ b/test/shutdown_SUITE.erl @@ -30,7 +30,7 @@ brutal_kill(_) -> doc("Shutdown Ranch listener with shutdown option set to brutal_kill."), Name = name(), {ok, ListenerSup} = ranch:start_listener(Name, - ranch_tcp, [{port, 0}, {shutdown, brutal_kill}], + ranch_tcp, #{shutdown => brutal_kill}, echo_protocol, []), Port = ranch:get_port(Name), {ok, _} = gen_tcp:connect("localhost", Port, []), @@ -50,7 +50,7 @@ infinity(_) -> doc("Shutdown Ranch listener with shutdown option set to infinity."), Name = name(), {ok, ListenerSup} = ranch:start_listener(Name, - ranch_tcp, [{port, 0}, {shutdown, infinity}], + ranch_tcp, #{shutdown => infinity}, echo_protocol, []), Port = ranch:get_port(Name), {ok, _} = gen_tcp:connect("localhost", Port, []), @@ -72,7 +72,7 @@ infinity_trap_exit(_) -> "until the protocol process terminates."), Name = name(), {ok, ListenerSup} = ranch:start_listener(Name, - ranch_tcp, [{port, 0}, {shutdown, infinity}], + ranch_tcp, #{shutdown => infinity}, trap_exit_protocol, []), Port = ranch:get_port(Name), {ok, _} = gen_tcp:connect("localhost", Port, []), @@ -101,7 +101,7 @@ timeout(_) -> doc("Shutdown Ranch listener with shutdown option set to 500ms."), Name = name(), {ok, ListenerSup} = ranch:start_listener(Name, - ranch_tcp, [{port, 0}, {shutdown, 500}], + ranch_tcp, #{shutdown => 500}, echo_protocol, []), Port = ranch:get_port(Name), {ok, _} = gen_tcp:connect("localhost", Port, []), @@ -123,7 +123,7 @@ timeout_trap_exit(_) -> "after the 500ms timeout."), Name = name(), {ok, ListenerSup} = ranch:start_listener(Name, - ranch_tcp, [{port, 0}, {shutdown, 500}], + ranch_tcp, #{shutdown => 500}, trap_exit_protocol, []), Port = ranch:get_port(Name), {ok, _} = gen_tcp:connect("localhost", Port, []), -- cgit v1.2.3