3333 close_all_user_connections /2 ,
3434 force_connection_event_refresh /1 , force_non_amqp_connection_event_refresh /1 ,
3535 handshake /2 , handshake /3 , tcp_host /1 ,
36- ranch_ref /1 , ranch_ref /2 , ranch_ref_of_protocol /1 , ranch_ref_to_protocol /1 ,
37- listener_of_protocol /1 , stop_ranch_listener_of_protocol /1 ,
36+ ranch_ref /1 , ranch_ref /2 , ranch_refs_of_protocol /1 , ranch_ref_to_protocol /1 ,
37+ listeners_of_protocol /1 , stop_ranch_listeners_of_protocol /1 ,
3838 list_local_connections_of_protocol /1 ]).
3939
4040% % Used by TCP-based transports, e.g. STOMP adapter
@@ -197,8 +197,7 @@ tcp_listener_spec(NamePrefix, {IPAddress, Port, Family}, SocketOpts,
197197 transient , infinity , supervisor , [tcp_listener_sup ]}.
198198
199199-spec ranch_ref (# listener {} | [{atom (), any ()}] | 'undefined' ) -> ranch :ref () | undefined .
200- ranch_ref (# listener {port = Port }) ->
201- [{IPAddress , Port , _Family } | _ ] = tcp_listener_addresses (Port ),
200+ ranch_ref (# listener {ip_address = IPAddress , port = Port }) ->
202201 {acceptor , IPAddress , Port };
203202ranch_ref (Listener ) when is_list (Listener ) ->
204203 Port = rabbit_misc :pget (port , Listener ),
@@ -230,9 +229,9 @@ ranch_ref(undefined) ->
230229ranch_ref (IPAddress , Port ) ->
231230 {acceptor , IPAddress , Port }.
232231
233- -spec ranch_ref_of_protocol (atom ()) -> ranch :ref () | undefined .
234- ranch_ref_of_protocol (Protocol ) ->
235- ranch_ref (listener_of_protocol (Protocol )) .
232+ -spec ranch_refs_of_protocol (atom ()) -> [ ranch :ref ()] .
233+ ranch_refs_of_protocol (Protocol ) ->
234+ [ ranch_ref (Listener ) || Listener <- listeners_of_protocol (Protocol )] .
236235
237236-spec ranch_ref_to_protocol (ranch :ref ()) -> atom () | undefined .
238237ranch_ref_to_protocol ({acceptor , IPAddress , Port }) ->
@@ -249,32 +248,32 @@ ranch_ref_to_protocol({acceptor, IPAddress, Port}) ->
249248ranch_ref_to_protocol (_ ) ->
250249 undefined .
251250
252- -spec listener_of_protocol (atom ()) -> # listener {}.
253- listener_of_protocol (Protocol ) ->
251+ -spec listeners_of_protocol (atom ()) -> [ # listener {}] .
252+ listeners_of_protocol (Protocol ) ->
254253 MatchSpec = # listener {
255254 protocol = Protocol ,
256255 _ = '_'
257256 },
258- case ets :match_object (? ETS_TABLE , MatchSpec ) of
259- [] -> undefined ;
260- [Row ] -> Row
261- end .
257+ ets :match_object (? ETS_TABLE , MatchSpec ).
262258
263- -spec stop_ranch_listener_of_protocol (atom ()) -> ok | {error , not_found }.
264- stop_ranch_listener_of_protocol (Protocol ) ->
265- case ranch_ref_of_protocol (Protocol ) of
266- undefined -> ok ;
267- Ref ->
268- ? LOG_DEBUG (" Stopping Ranch listener for protocol ~ts " , [Protocol ]),
269- ranch :stop_listener (Ref )
259+ -spec stop_ranch_listeners_of_protocol (atom ()) -> ok .
260+ stop_ranch_listeners_of_protocol (Protocol ) ->
261+ case ranch_refs_of_protocol (Protocol ) of
262+ [] ->
263+ ok ;
264+ Refs ->
265+ ? LOG_DEBUG (" Stopping Ranch listeners for protocol ~ts " , [Protocol ]),
266+ lists :foreach (fun ranch :stop_listener /1 , Refs )
270267 end .
271268
272269-spec list_local_connections_of_protocol (atom ()) -> [pid ()].
273270list_local_connections_of_protocol (Protocol ) ->
274- case ranch_ref_of_protocol (Protocol ) of
275- undefined -> [];
276- AcceptorRef -> ranch :procs (AcceptorRef , connections )
277- end .
271+ Refs = ranch_refs_of_protocol (Protocol ),
272+ lists :flatten (
273+ lists :map (
274+ fun (Ref ) ->
275+ ranch :procs (Ref , connections )
276+ end , Refs )).
278277
279278-spec start_tcp_listener (
280279 listener_config (), integer ()) -> 'ok' | {'error' , term ()}.
0 commit comments