24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-18 22:15:20 +02:00

Add validator for 'accept_interval' listening option

This commit is contained in:
Evgeniy Khramtsov 2018-04-30 11:52:00 +03:00
parent 0bd4d1aade
commit 4ea481d1dd
9 changed files with 27 additions and 37 deletions

View File

@ -1038,6 +1038,8 @@ listen_opt_type(inet) -> fun(B) when is_boolean(B) -> B end;
listen_opt_type(inet6) -> fun(B) when is_boolean(B) -> B end;
listen_opt_type(backlog) ->
fun(I) when is_integer(I), I>0 -> I end;
listen_opt_type(accept_interval) ->
fun(I) when is_integer(I), I>=0 -> I end;
listen_opt_type(O) ->
StreamOpts = mod_stream_mgmt:mod_options(?MYNAME),
case lists:keyfind(O, 1, StreamOpts) of
@ -1045,7 +1047,7 @@ listen_opt_type(O) ->
[access, shaper, certfile, ciphers, dhfile, cafile,
protocol_options, tls, tls_compression, starttls,
starttls_required, tls_verify, zlib, max_fsm_queue,
backlog, inet, inet6];
backlog, inet, inet6, accept_interval];
_ ->
?ERROR_MSG("Listening option '~s' is ignored: use '~s' "
"option from mod_stream_mgmt module", [O, O]),

View File

@ -947,6 +947,8 @@ listen_opt_type(inet) -> fun(B) when is_boolean(B) -> B end;
listen_opt_type(inet6) -> fun(B) when is_boolean(B) -> B end;
listen_opt_type(backlog) ->
fun(I) when is_integer(I), I>0 -> I end;
listen_opt_type(accept_interval) ->
fun(I) when is_integer(I), I>=0 -> I end;
listen_opt_type(_) ->
%% TODO
fun(A) -> A end.

View File

@ -256,36 +256,7 @@ get_ip_tuple(IPOpt, _IPVOpt) ->
IPOpt.
accept(ListenSocket, Module, Opts) ->
IntervalOpt =
case proplists:get_value(accept_interval, Opts) of
[{linear, [I1_, T1_, T2_, I2_]}] ->
{linear, I1_, T1_, T2_, I2_};
I_ -> I_
end,
Interval =
case IntervalOpt of
undefined ->
0;
I when is_integer(I), I >= 0 ->
I;
{linear, I1, T1, T2, I2}
when is_integer(I1),
is_integer(T1),
is_integer(T2),
is_integer(I2),
I1 >= 0,
I2 >= 0,
T2 > 0 ->
{MSec, Sec, _USec} = os:timestamp(),
TS = MSec * 1000000 + Sec,
{linear, I1, TS + T1, T2, I2};
I ->
?WARNING_MSG("There is a problem in the configuration: "
"~p is a wrong accept_interval value. "
"Using 0 as fallback",
[I]),
0
end,
Interval = proplists:get_value(accept_interval, Opts, 0),
accept(ListenSocket, Module, Opts, Interval).
accept(ListenSocket, Module, Opts, Interval) ->

View File

@ -388,6 +388,9 @@ listen_opt_type(inet) -> fun(B) when is_boolean(B) -> B end;
listen_opt_type(inet6) -> fun(B) when is_boolean(B) -> B end;
listen_opt_type(backlog) ->
fun(I) when is_integer(I), I>0 -> I end;
listen_opt_type(accept_interval) ->
fun(I) when is_integer(I), I>=0 -> I end;
listen_opt_type(_) ->
[shaper, certfile, ciphers, dhfile, cafile, protocol_options,
tls_compression, tls, max_fsm_queue, backlog, inet, inet6].
tls_compression, tls, max_fsm_queue, backlog, inet, inet6,
accept_interval].

View File

@ -341,7 +341,9 @@ listen_opt_type(inet) -> fun(B) when is_boolean(B) -> B end;
listen_opt_type(inet6) -> fun(B) when is_boolean(B) -> B end;
listen_opt_type(backlog) ->
fun(I) when is_integer(I), I>0 -> I end;
listen_opt_type(accept_interval) ->
fun(I) when is_integer(I), I>=0 -> I end;
listen_opt_type(_) ->
[access, shaper_rule, certfile, ciphers, dhfile, cafile, tls,
protocol_options, tls_compression, password, hosts, check_from,
max_fsm_queue, global_routes, backlog, inet, inet6].
max_fsm_queue, global_routes, backlog, inet, inet6, accept_interval].

View File

@ -93,8 +93,10 @@ listen_opt_type(certfile) ->
end;
listen_opt_type(tls) ->
fun(B) when is_boolean(B) -> B end;
listen_opt_type(accept_interval) ->
fun(I) when is_integer(I), I>=0 -> I end;
listen_opt_type(_) ->
[tls, certfile].
[tls, certfile, accept_interval].
%%%===================================================================
%%% Internal functions

View File

@ -174,8 +174,10 @@ listen_opt_type(server_name) ->
fun iolist_to_binary/1;
listen_opt_type(backlog) ->
fun(I) when is_integer(I), I>0 -> I end;
listen_opt_type(accept_interval) ->
fun(I) when is_integer(I), I>=0 -> I end;
listen_opt_type(_) ->
[shaper, auth_type, auth_realm, tls, certfile, turn_min_port,
turn_max_port, turn_max_allocations, turn_max_permissions,
server_name, backlog].
server_name, backlog, accept_interval].
-endif.

View File

@ -585,5 +585,8 @@ listen_opt_type(inet) -> fun(B) when is_boolean(B) -> B end;
listen_opt_type(inet6) -> fun(B) when is_boolean(B) -> B end;
listen_opt_type(backlog) ->
fun(I) when is_integer(I), I>0 -> I end;
listen_opt_type(accept_interval) ->
fun(I) when is_integer(I), I>=0 -> I end;
listen_opt_type(_) ->
[access_commands, maxsessions, timeout, backlog, inet, inet6].
[access_commands, maxsessions, timeout, backlog, inet, inet6,
accept_interval].

View File

@ -294,10 +294,13 @@ listen_opt_type(recbuf) ->
fun (I) when is_integer(I), I > 0 -> I end;
listen_opt_type(shaper) -> fun acl:shaper_rules_validator/1;
listen_opt_type(sndbuf) ->
fun (I) when is_integer(I), I > 0 -> I end.
fun (I) when is_integer(I), I > 0 -> I end;
listen_opt_type(accept_interval) ->
fun(I) when is_integer(I), I>=0 -> I end.
listen_options() ->
[{auth_type, anonymous},
{recbuf, 8192},
{sndbuf, 8192},
{accept_interval, 0},
{shaper, none}].