diff options
author | juhlig <j.uhlig@mailingwork.de> | 2019-07-17 16:02:47 +0200 |
---|---|---|
committer | Loïc Hoguin <essen@ninenines.eu> | 2019-07-18 09:35:56 +0200 |
commit | af739162fd43d46f2562af96c56147054457518e (patch) | |
tree | 51d5c937c3ee0af17c8cbe75d0f7bcd70aacfa91 | |
parent | d017c0f5860bc1a5c775c9a61db407e29c575f80 (diff) | |
download | ranch-2.0.0-rc.1.tar.gz ranch-2.0.0-rc.1.tar.bz2 ranch-2.0.0-rc.1.zip |
Return listener info as a map2.0.0-rc.1
-rw-r--r-- | doc/src/manual/ranch.info.asciidoc | 11 | ||||
-rw-r--r-- | src/ranch.erl | 39 | ||||
-rw-r--r-- | test/acceptor_SUITE.erl | 163 |
3 files changed, 101 insertions, 112 deletions
diff --git a/doc/src/manual/ranch.info.asciidoc b/doc/src/manual/ranch.info.asciidoc index 69a8818..651daf2 100644 --- a/doc/src/manual/ranch.info.asciidoc +++ b/doc/src/manual/ranch.info.asciidoc @@ -8,10 +8,10 @@ ranch:info - Overview of Ranch listeners [source,erlang] ---- -info() -> [{Ref, Info}] +info() -> #{Ref := Info} info(Ref) -> Info -Info :: [{Key :: atom(), Value :: any()}] +Info :: #{Key :: atom() := Value :: any()} ---- Overview of Ranch listeners. @@ -31,7 +31,6 @@ pid:: Pid of the listener's top-level supervisor. status:: Listener status, either running or suspended. ip:: Interface Ranch listens on. port:: Port number Ranch listens on. -num_acceptors:: Number of acceptor processes. max_connections:: Maximum number of connections per connection supervisor. active_connections:: Number of active connections. all_connections:: Number of connections, including those removed from the count. @@ -40,8 +39,10 @@ transport_options:: Transport options. protocol:: Protocol module. protocol_options:: Protocol options. -// @todo I mistakenly removed the num_acceptors key, -// it should be added back. +== Changelog + +* *2.0*: The listener info is now returned as a map. +* *2.0*: The `num_acceptors` key has been removed. == Examples diff --git a/src/ranch.erl b/src/ranch.erl index 94727ea..08eebfc 100644 --- a/src/ranch.erl +++ b/src/ranch.erl @@ -315,12 +315,17 @@ get_protocol_options(Ref) -> set_protocol_options(Ref, Opts) -> ranch_server:set_protocol_options(Ref, Opts). --spec info() -> [{any(), [{atom(), any()}]}]. +-spec info() -> #{ref() := #{atom() := term()}}. info() -> - [{Ref, listener_info(Ref, Pid)} - || {Ref, Pid} <- ranch_server:get_listener_sups()]. + lists:foldl( + fun ({Ref, Pid}, Acc) -> + Acc#{Ref => listener_info(Ref, Pid)} + end, + #{}, + ranch_server:get_listener_sups() + ). --spec info(ref()) -> [{atom(), any()}]. +-spec info(ref()) -> #{atom() := term()}. info(Ref) -> Pid = ranch_server:get_listener_sup(Ref), listener_info(Ref, Pid). @@ -337,19 +342,19 @@ listener_info(Ref, Pid) -> MaxConns = get_max_connections(Ref), TransOpts = ranch_server:get_transport_options(Ref), ProtoOpts = get_protocol_options(Ref), - [ - {pid, Pid}, - {status, Status}, - {ip, IP}, - {port, Port}, - {max_connections, MaxConns}, - {active_connections, get_connections(Ref, active)}, - {all_connections, get_connections(Ref, all)}, - {transport, Transport}, - {transport_options, TransOpts}, - {protocol, Protocol}, - {protocol_options, ProtoOpts} - ]. + #{ + pid => Pid, + status => Status, + ip => IP, + port => Port, + max_connections => MaxConns, + active_connections => get_connections(Ref, active), + all_connections => get_connections(Ref, all), + transport => Transport, + transport_options => TransOpts, + protocol => Protocol, + protocol_options => ProtoOpts + }. -spec procs(ref(), acceptors | connections) -> [pid()]. procs(Ref, Type) -> diff --git a/test/acceptor_SUITE.erl b/test/acceptor_SUITE.erl index 1cccabc..8748201 100644 --- a/test/acceptor_SUITE.erl +++ b/test/acceptor_SUITE.erl @@ -137,47 +137,41 @@ misc_info(_) -> {ok, _} = gen_tcp:connect("localhost", Port1, [binary, {active, false}, {packet, raw}]), receive after 250 -> ok end, %% Confirm the info returned by Ranch is correct. - [ - {{misc_info, act}, [ - {pid, Pid2}, - {status, _}, - {ip, _}, - {port, Port2}, - {max_connections, infinity}, %% Option was modified. - {active_connections, 0}, - {all_connections, 0}, - {transport, ranch_tcp}, - {transport_options, #{num_acceptors := 2}}, - {protocol, active_echo_protocol}, - {protocol_options, {}} - ]}, - {{misc_info, ssl}, [ - {pid, Pid3}, - {status, _}, - {ip, _}, - {port, Port3}, - {max_connections, 1024}, - {active_connections, 0}, - {all_connections, 0}, - {transport, ranch_ssl}, - {transport_options, #{num_acceptors := 3, socket_opts := Opts}}, - {protocol, echo_protocol}, - {protocol_options, [{}]} - ]}, - {{misc_info, tcp}, [ - {pid, Pid1}, - {status, _}, - {ip, _}, - {port, Port1}, - {max_connections, 1024}, - {active_connections, 2}, - {all_connections, 5}, - {transport, ranch_tcp}, - {transport_options, #{num_acceptors := 1}}, - {protocol, remove_conn_and_wait_protocol}, - {protocol_options, [{remove, false, 2500}]} %% Option was modified. - ]} - ] = do_get_listener_info(misc_info), + #{ + {misc_info, act} := #{ + pid := Pid2, + port := Port2, + max_connections := infinity, %% Option was modified. + active_connections := 0, + all_connections := 0, + transport := ranch_tcp, + transport_options := #{num_acceptors := 2}, + protocol := active_echo_protocol, + protocol_options := {} + }, + {misc_info, ssl} := #{ + pid := Pid3, + port := Port3, + max_connections := 1024, + active_connections := 0, + all_connections := 0, + transport := ranch_ssl, + transport_options := #{num_acceptors := 3, socket_opts := Opts}, + protocol := echo_protocol, + protocol_options := [{}] + }, + {misc_info, tcp} := #{ + pid := Pid1, + port := Port1, + max_connections := 1024, + active_connections := 2, + all_connections := 5, + transport := ranch_tcp, + transport_options := #{num_acceptors := 1}, + protocol := remove_conn_and_wait_protocol, + protocol_options := [{remove, false, 2500}] %% Option was modified. + } + } = ranch:info(), %% Get acceptors. [_] = ranch:procs({misc_info, tcp}, acceptors), [_, _] = ranch:procs({misc_info, act}, acceptors), @@ -224,47 +218,41 @@ misc_info_embedded(_) -> {ok, _} = gen_tcp:connect("localhost", Port1, [binary, {active, false}, {packet, raw}]), receive after 250 -> ok end, %% Confirm the info returned by Ranch is correct. - [ - {{misc_info_embedded, act}, [ - {pid, Pid2}, - {status, _}, - {ip, _}, - {port, Port2}, - {max_connections, infinity}, %% Option was modified. - {active_connections, 0}, - {all_connections, 0}, - {transport, ranch_tcp}, - {transport_options, #{num_acceptors := 2}}, - {protocol, active_echo_protocol}, - {protocol_options, {}} - ]}, - {{misc_info_embedded, ssl}, [ - {pid, Pid3}, - {status, _}, - {ip, _}, - {port, Port3}, - {max_connections, 1024}, - {active_connections, 0}, - {all_connections, 0}, - {transport, ranch_ssl}, - {transport_options, #{num_acceptors := 3, socket_opts := Opts}}, - {protocol, echo_protocol}, - {protocol_options, [{}]} - ]}, - {{misc_info_embedded, tcp}, [ - {pid, Pid1}, - {status, _}, - {ip, _}, - {port, Port1}, - {max_connections, 1024}, - {active_connections, 2}, - {all_connections, 5}, - {transport, ranch_tcp}, - {transport_options, #{num_acceptors := 1}}, - {protocol, remove_conn_and_wait_protocol}, - {protocol_options, [{remove, false, 2500}]} %% Option was modified. - ]} - ] = do_get_listener_info(misc_info_embedded), + #{ + {misc_info_embedded, act} := #{ + pid := Pid2, + port := Port2, + max_connections := infinity, %% Option was modified. + active_connections := 0, + all_connections := 0, + transport := ranch_tcp, + transport_options := #{num_acceptors := 2}, + protocol := active_echo_protocol, + protocol_options := {} + }, + {misc_info_embedded, ssl} := #{ + pid := Pid3, + port := Port3, + max_connections := 1024, + active_connections := 0, + all_connections := 0, + transport := ranch_ssl, + transport_options := #{num_acceptors := 3, socket_opts := Opts}, + protocol := echo_protocol, + protocol_options := [{}] + }, + {misc_info_embedded, tcp} := #{ + pid := Pid1, + port := Port1, + max_connections := 1024, + active_connections := 2, + all_connections := 5, + transport := ranch_tcp, + transport_options := #{num_acceptors := 1}, + protocol := remove_conn_and_wait_protocol, + protocol_options := [{remove, false, 2500}] %% Option was modified. + } + } = ranch:info(), %% Get acceptors. [_] = ranch:procs({misc_info_embedded, tcp}, acceptors), [_, _] = ranch:procs({misc_info_embedded, act}, acceptors), @@ -276,24 +264,19 @@ misc_info_embedded(_) -> %% Stop embedded tcp listener and ensure it is gone. ok = embedded_sup:stop_listener(SupPid, {misc_info_embedded, tcp}), timer:sleep(500), - [{{misc_info_embedded, act}, _}, {{misc_info_embedded, ssl}, _}] = - do_get_listener_info(misc_info_embedded), + false = maps:is_key({misc_info_embedded, tcp}, ranch:info()), %% Stop embedded act listener and ensure it is gone. ok = embedded_sup:stop_listener(SupPid, {misc_info_embedded, act}), timer:sleep(500), - [{{misc_info_embedded, ssl}, _}] = - do_get_listener_info(misc_info_embedded), + false = maps:is_key({misc_info_embedded, act}, ranch:info()), %% Stop embedded ssl listener and ensure it is gone. ok = embedded_sup:stop_listener(SupPid, {misc_info_embedded, ssl}), timer:sleep(500), - [] = do_get_listener_info(misc_info_embedded), + false = maps:is_key({misc_info_embedded, ssl}, ranch:info()), %% Stop embedded supervisor. embedded_sup:stop(SupPid), ok. -do_get_listener_info(ListenerGroup) -> - lists:sort([L || L={{G, _}, _} <- ranch:info(), G=:=ListenerGroup]). - misc_opts_logger(_) -> doc("Confirm that messages are sent via the configured logger module."), register(misc_opts_logger, self()), |