41
41
%%used by TCP-based transports, e.g. STOMP adapter
42
42
-export([check_tcp_listener_address/3]).
44
-export([tcp_listener_started/2, tcp_listener_stopped/2,
44
-export([tcp_listener_started/3, tcp_listener_stopped/3,
45
45
start_client/1, start_ssl_client/2]).
47
47
-include("rabbit.hrl").
68
68
-spec(start/0 :: () -> 'ok').
69
69
-spec(start_tcp_listener/2 :: (hostname(), ip_port()) -> 'ok').
70
-spec(start_ssl_listener/3 :: (hostname(), ip_port(), [rabbit_types:info()])
70
-spec(start_ssl_listener/3 :: (hostname(), ip_port(), rabbit_types:infos())
72
72
-spec(stop_tcp_listener/2 :: (hostname(), ip_port()) -> 'ok').
73
73
-spec(active_listeners/0 :: () -> [rabbit_types:listener()]).
74
74
-spec(node_listeners/1 :: (node()) -> [rabbit_types:listener()]).
75
75
-spec(connections/0 :: () -> [rabbit_types:connection()]).
76
-spec(connection_info_keys/0 :: () -> [rabbit_types:info_key()]).
76
-spec(connection_info_keys/0 :: () -> rabbit_types:info_keys()).
77
77
-spec(connection_info/1 ::
78
(rabbit_types:connection()) -> [rabbit_types:info()]).
78
(rabbit_types:connection()) -> rabbit_types:infos()).
79
79
-spec(connection_info/2 ::
80
(rabbit_types:connection(), [rabbit_types:info_key()])
81
-> [rabbit_types:info()]).
82
-spec(connection_info_all/0 :: () -> [[rabbit_types:info()]]).
80
(rabbit_types:connection(), rabbit_types:info_keys())
81
-> rabbit_types:infos()).
82
-spec(connection_info_all/0 :: () -> [rabbit_types:infos()]).
83
83
-spec(connection_info_all/1 ::
84
([rabbit_types:info_key()]) -> [[rabbit_types:info()]]).
84
(rabbit_types:info_keys()) -> [rabbit_types:infos()]).
85
85
-spec(close_connection/2 :: (pid(), string()) -> 'ok').
86
86
-spec(on_node_down/1 :: (node()) -> 'ok').
87
87
-spec(check_tcp_listener_address/3 ::
160
160
{IPAddress, Name}.
162
162
start_tcp_listener(Host, Port) ->
163
start_listener(Host, Port, "TCP Listener",
163
start_listener(Host, Port, amqp, "TCP Listener",
164
164
{?MODULE, start_client, []}).
166
166
start_ssl_listener(Host, Port, SslOpts) ->
167
start_listener(Host, Port, "SSL Listener",
167
start_listener(Host, Port, 'amqp/ssl', "SSL Listener",
168
168
{?MODULE, start_ssl_client, [SslOpts]}).
170
start_listener(Host, Port, Label, OnConnect) ->
170
start_listener(Host, Port, Protocol, Label, OnConnect) ->
171
171
{IPAddress, Name} =
172
172
check_tcp_listener_address(rabbit_tcp_listener_sup, Host, Port),
173
173
{ok,_} = supervisor:start_child(
176
176
{tcp_listener_sup, start_link,
177
177
[IPAddress, Port, ?RABBIT_TCP_OPTS ,
178
{?MODULE, tcp_listener_started, []},
179
{?MODULE, tcp_listener_stopped, []},
178
{?MODULE, tcp_listener_started, [Protocol]},
179
{?MODULE, tcp_listener_stopped, [Protocol]},
180
180
OnConnect, Label]},
181
181
transient, infinity, supervisor, [tcp_listener_sup]}),
188
188
ok = supervisor:delete_child(rabbit_sup, Name),
191
tcp_listener_started(IPAddress, Port) ->
191
tcp_listener_started(Protocol, IPAddress, Port) ->
192
%% We need the ip to distinguish e.g. 0.0.0.0 and 127.0.0.1
193
%% We need the host so we can distinguish multiple instances of the above
192
195
ok = mnesia:dirty_write(
194
197
#listener{node = node(),
196
199
host = tcp_host(IPAddress),
200
ip_address = IPAddress,
199
tcp_listener_stopped(IPAddress, Port) ->
203
tcp_listener_stopped(Protocol, IPAddress, Port) ->
200
204
ok = mnesia:dirty_delete_object(
202
206
#listener{node = node(),
204
208
host = tcp_host(IPAddress),
209
ip_address = IPAddress,
207
212
active_listeners() ->