diff options
| author | Michael Klishin <michael@clojurewerkz.org> | 2020-06-24 04:27:35 +0300 |
|---|---|---|
| committer | Michael Klishin <michael@clojurewerkz.org> | 2020-07-14 03:50:30 +0300 |
| commit | f0a44df7fba9349bf7fdb412acf5555fd5316f69 (patch) | |
| tree | 957a6266d139689a90295e208f49765eec00a94a | |
| parent | ac461e9e8ecb504c42405892fea583f037645cce (diff) | |
| download | rabbitmq-server-git-f0a44df7fba9349bf7fdb412acf5555fd5316f69.tar.gz | |
Unify Ranch ref construction for all listeners
This makes the refs predictable and easy to compute
from a listener record. Then suspending all listeners
becomes a lot simpler.
While at it, make protocol applications clean up
their listeners when they stop. This way tests
and other callers that have to stop the app
would not need to know anything about
its listeners.
Part of rabbitmq/rabbitmq-server#2321
| -rw-r--r-- | src/rabbit_networking.erl | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/rabbit_networking.erl b/src/rabbit_networking.erl index e492954a7e..dc9f0204c1 100644 --- a/src/rabbit_networking.erl +++ b/src/rabbit_networking.erl @@ -28,7 +28,9 @@ connection_info_all/0, connection_info_all/1, emit_connection_info_all/4, emit_connection_info_local/3, close_connection/2, close_connections/2, - force_connection_event_refresh/1, handshake/2, tcp_host/1, ranch_ref/2]). + force_connection_event_refresh/1, handshake/2, tcp_host/1, + ranch_ref/1, ranch_ref/2, ranch_ref_of_protocol/1, + listener_of_protocol/1]). %% Used by TCP-based transports, e.g. STOMP adapter -export([tcp_listener_addresses/1, tcp_listener_spec/9, @@ -196,12 +198,39 @@ tcp_listener_spec(NamePrefix, {IPAddress, Port, Family}, SocketOpts, modules => [tcp_listener_sup] }. +-spec ranch_ref(#listener{} | [{atom(), any()}]) -> ranch:ref(). +ranch_ref(#listener{port = Port}) -> + [{IPAddress, Port, _Family} | _] = tcp_listener_addresses(Port), + {acceptor, IPAddress, Port}; +ranch_ref(Listener) when is_list(Listener) -> + Port = rabbit_misc:pget(port, Listener), + [{IPAddress, Port, _Family} | _] = tcp_listener_addresses(Port), + {acceptor, IPAddress, Port}. + -spec ranch_ref(inet:ip_address(), ip_port()) -> ranch:ref(). %% Returns a reference that identifies a TCP listener in Ranch. ranch_ref(IPAddress, Port) -> {acceptor, IPAddress, Port}. +-spec ranch_ref_of_protocol(atom()) -> ranch:ref(). +ranch_ref_of_protocol(Protocol) -> + ranch_ref(listener_of_protocol(Protocol)). + +-spec listener_of_protocol(atom()) -> #listener{}. +listener_of_protocol(Protocol) -> + rabbit_misc:execute_mnesia_transaction( + fun() -> + MatchSpec = #listener{ + node = node(), + protocol = Protocol, + _ = '_' + }, + case mnesia:match_object(rabbit_listener, MatchSpec, read) of + [] -> undefined; + [Row] -> Row + end + end). -spec start_tcp_listener( listener_config(), integer()) -> 'ok' | {'error', term()}. |
