summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Klishin <michael@clojurewerkz.org>2020-05-18 12:57:35 +0300
committerMichael Klishin <michael@clojurewerkz.org>2020-07-14 03:50:29 +0300
commit029ea3ef508c2838be9f7b63fa95d5719640658f (patch)
tree16f947048d4ed941e65ee00a463763d4a685b49b
parente86fa81a3f90599d03b2f9beaaa56cfb6a4226f1 (diff)
downloadrabbitmq-server-git-029ea3ef508c2838be9f7b63fa95d5719640658f.tar.gz
Extract a function that computes Ranch listener references
-rw-r--r--src/rabbit_networking.erl20
-rw-r--r--src/tcp_listener_sup.erl5
2 files changed, 17 insertions, 8 deletions
diff --git a/src/rabbit_networking.erl b/src/rabbit_networking.erl
index d54e50a1db..f499e4bcfc 100644
--- a/src/rabbit_networking.erl
+++ b/src/rabbit_networking.erl
@@ -28,7 +28,7 @@
connection_info_all/0, connection_info_all/1,
emit_connection_info_all/4, emit_connection_info_local/3,
close_connection/2, force_connection_event_refresh/1,
- handshake/2, tcp_host/1]).
+ handshake/2, tcp_host/1, ranch_ref/2]).
%% Used by TCP-based transports, e.g. STOMP adapter
-export([tcp_listener_addresses/1, tcp_listener_spec/9,
@@ -184,9 +184,21 @@ tcp_listener_spec(NamePrefix, {IPAddress, Port, Family}, SocketOpts,
{?MODULE, tcp_listener_started, [Protocol, SocketOpts]},
{?MODULE, tcp_listener_stopped, [Protocol, SocketOpts]},
NumAcceptors, Label],
- {rabbit_misc:tcp_name(NamePrefix, IPAddress, Port),
- {tcp_listener_sup, start_link, Args},
- transient, infinity, supervisor, [tcp_listener_sup]}.
+ #{
+ id => rabbit_misc:tcp_name(NamePrefix, IPAddress, Port),
+ start => {tcp_listener_sup, start_link, Args},
+ restart => transient,
+ shutdown => infinity,
+ type => supervisor,
+ modules => [tcp_listener_sup]
+ }.
+
+-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 start_tcp_listener(
listener_config(), integer()) -> 'ok' | {'error', term()}.
diff --git a/src/tcp_listener_sup.erl b/src/tcp_listener_sup.erl
index 2d384bb4dc..76ff814ff4 100644
--- a/src/tcp_listener_sup.erl
+++ b/src/tcp_listener_sup.erl
@@ -17,11 +17,8 @@
-behaviour(supervisor).
-export([start_link/10]).
-
-export([init/1]).
-%%----------------------------------------------------------------------------
-
-type mfargs() :: {atom(), atom(), [any()]}.
-spec start_link
@@ -57,7 +54,7 @@ init({IPAddress, Port, Transport, SocketOpts, ProtoSup, ProtoOpts, OnStartup, On
type => worker,
modules => [tcp_listener]
},
- RanchChildSpec = ranch:child_spec({acceptor, IPAddress, Port},
+ RanchChildSpec = ranch:child_spec(rabbit_networking:ranch_ref(IPAddress, Port),
Transport, RanchListenerOpts,
ProtoSup, ProtoOpts),
{ok, {Flags, [RanchChildSpec, OurChildSpec]}}.