Refactor to use ranch:start_listener/5
and avoid a warning from Ranch. Closes #59. References rabbitmq/rabbitmq-server#2069.
This commit is contained in:
parent
3565a14bc6
commit
b4f51bf2aa
|
|
@ -66,10 +66,17 @@ mqtt_init() ->
|
||||||
|
|
||||||
start_tcp_listener(TCPConf0, CowboyOpts) ->
|
start_tcp_listener(TCPConf0, CowboyOpts) ->
|
||||||
{TCPConf, IpStr, Port} = get_tcp_conf(TCPConf0),
|
{TCPConf, IpStr, Port} = get_tcp_conf(TCPConf0),
|
||||||
MaxConnections = get_max_connections(),
|
RanchTransportOpts = #{
|
||||||
case ranch:start_listener(web_mqtt, get_env(num_tcp_acceptors, 10),
|
socket_opts => TCPConf,
|
||||||
ranch_tcp, [{max_connections, MaxConnections}|TCPConf],
|
connection_type => supervisor,
|
||||||
rabbit_web_mqtt_connection_sup, CowboyOpts) of
|
max_connections => get_max_connections(),
|
||||||
|
num_acceptors => get_env(num_tcp_acceptors, 10)
|
||||||
|
},
|
||||||
|
case ranch:start_listener(web_mqtt,
|
||||||
|
ranch_tcp,
|
||||||
|
RanchTransportOpts,
|
||||||
|
rabbit_web_mqtt_connection_sup,
|
||||||
|
CowboyOpts) of
|
||||||
{ok, _} -> ok;
|
{ok, _} -> ok;
|
||||||
{error, {already_started, _}} -> ok;
|
{error, {already_started, _}} -> ok;
|
||||||
{error, ErrTCP} ->
|
{error, ErrTCP} ->
|
||||||
|
|
@ -86,13 +93,17 @@ start_tcp_listener(TCPConf0, CowboyOpts) ->
|
||||||
start_tls_listener(TLSConf0, CowboyOpts) ->
|
start_tls_listener(TLSConf0, CowboyOpts) ->
|
||||||
rabbit_networking:ensure_ssl(),
|
rabbit_networking:ensure_ssl(),
|
||||||
{TLSConf, TLSIpStr, TLSPort} = get_tls_conf(TLSConf0),
|
{TLSConf, TLSIpStr, TLSPort} = get_tls_conf(TLSConf0),
|
||||||
MaxConnections = get_max_connections(),
|
RanchTransportOpts = #{
|
||||||
{ok, _} = ranch:start_listener(web_mqtt_secure, get_env(num_ssl_acceptors, 10),
|
socket_opts => TLSConf,
|
||||||
ranch_ssl, [{max_connections, MaxConnections}|TLSConf],
|
connection_type => supervisor,
|
||||||
rabbit_web_mqtt_connection_sup, CowboyOpts),
|
max_connections => get_max_connections(),
|
||||||
case ranch:start_listener(web_mqtt_secure, get_env(num_ssl_acceptors, 10),
|
num_acceptors => get_env(num_ssl_acceptors, 10)
|
||||||
ranch_ssl, [{max_connections, MaxConnections}|TLSConf],
|
},
|
||||||
rabbit_web_mqtt_connection_sup, CowboyOpts) of
|
case ranch:start_listener(web_mqtt_secure,
|
||||||
|
ranch_ssl,
|
||||||
|
RanchTransportOpts,
|
||||||
|
rabbit_web_mqtt_connection_sup,
|
||||||
|
CowboyOpts) of
|
||||||
{ok, _} -> ok;
|
{ok, _} -> ok;
|
||||||
{error, {already_started, _}} -> ok;
|
{error, {already_started, _}} -> ok;
|
||||||
{error, ErrTLS} ->
|
{error, ErrTLS} ->
|
||||||
|
|
@ -115,20 +126,18 @@ listener_started(Protocol, Listener) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
get_tcp_conf(TCPConf0) ->
|
get_tcp_conf(TCPConf0) ->
|
||||||
TCPConf1 = [{connection_type, supervisor}|TCPConf0],
|
TCPConf1 = case proplists:get_value(port, TCPConf0) of
|
||||||
TCPConf2 = case proplists:get_value(port, TCPConf1) of
|
undefined -> [{port, 15675}|TCPConf0];
|
||||||
undefined -> [{port, 15675}|TCPConf1];
|
_ -> TCPConf0
|
||||||
_ -> TCPConf1
|
|
||||||
end,
|
end,
|
||||||
get_ip_port(TCPConf2).
|
get_ip_port(TCPConf1).
|
||||||
|
|
||||||
get_tls_conf(TLSConf0) ->
|
get_tls_conf(TLSConf0) ->
|
||||||
TLSConf1 = [{connection_type, supervisor}|TLSConf0],
|
TLSConf1 = case proplists:get_value(port, TLSConf0) of
|
||||||
TLSConf2 = case proplists:get_value(port, TLSConf1) of
|
undefined -> [{port, 15675}|proplists:delete(port, TLSConf0)];
|
||||||
undefined -> [{port, 15675}|proplists:delete(port, TLSConf1)];
|
_ -> TLSConf0
|
||||||
_ -> TLSConf1
|
|
||||||
end,
|
end,
|
||||||
get_ip_port(TLSConf2).
|
get_ip_port(TLSConf1).
|
||||||
|
|
||||||
get_ip_port(Conf0) ->
|
get_ip_port(Conf0) ->
|
||||||
IpStr = proplists:get_value(ip, Conf0),
|
IpStr = proplists:get_value(ip, Conf0),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue