Use new ranch api to elimate warning log for deprecated apis

This commit is contained in:
Gilbert Wong 2019-05-30 02:07:21 +08:00 committed by Gilbert
parent 9715234626
commit 365832f945
1 changed files with 8 additions and 6 deletions

View File

@ -89,16 +89,18 @@ ranch_opts(Options) ->
NumAcceptors = proplists:get_value(acceptors, Options, 4),
MaxConnections = proplists:get_value(max_connections, Options, 1024),
TcpOptions = proplists:get_value(tcp_options, Options, []),
RanchOpts = [{num_acceptors, NumAcceptors}, {max_connections, MaxConnections} | TcpOptions],
RanchOpts = #{ num_acceptors => NumAcceptors
, max_connections => MaxConnections
, socket_opts => TcpOptions},
case proplists:get_value(ssl_options, Options) of
undefined -> RanchOpts;
SslOptions -> RanchOpts ++ SslOptions
SslOptions -> RanchOpts#{socket_opts => TcpOptions ++ SslOptions}
end.
with_port(Port, Opts) when is_integer(Port) ->
[{port, Port}|Opts];
with_port({Addr, Port}, Opts) ->
[{ip, Addr}, {port, Port}|Opts].
with_port(Port, Opts = #{socket_opts := SocketOption}) when is_integer(Port) ->
Opts#{socket_opts => [{port, Port}| SocketOption]};
with_port({Addr, Port}, Opts = #{socket_opts := SocketOption}) ->
Opts#{socket_opts => [{ip, Addr}, {port, Port}| SocketOption]}.
%% @doc Restart all listeners
-spec(restart() -> ok).