aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ranch.erl15
-rw-r--r--src/ranch_conns_sup.erl5
2 files changed, 14 insertions, 6 deletions
diff --git a/src/ranch.erl b/src/ranch.erl
index 576f122..07416fd 100644
--- a/src/ranch.erl
+++ b/src/ranch.erl
@@ -59,7 +59,7 @@
type := Type,
callback := Callback,
treshold := non_neg_integer(),
- cooldown := non_neg_integer()
+ cooldown => non_neg_integer()
}.
-type alarm_num_connections() :: alarm(num_connections, fun((ref(), term(), pid(), [pid()]) -> any())).
@@ -165,11 +165,16 @@ validate_transport_opt(socket_opts, _, _) ->
validate_transport_opt(_, _, _) ->
false.
-validate_alarm(#{type := num_connections, treshold := Treshold,
- callback := Callback, cooldown := Cooldown}) ->
+validate_alarm(Alarm = #{type := num_connections, treshold := Treshold,
+ callback := Callback}) ->
is_integer(Treshold) andalso Treshold >= 0
- andalso is_integer(Cooldown) andalso Cooldown >= 0
- andalso is_function(Callback, 4);
+ andalso is_function(Callback, 4)
+ andalso case Alarm of
+ #{cooldown := Cooldown} ->
+ is_integer(Cooldown) andalso Cooldown >= 0;
+ _ ->
+ true
+ end;
validate_alarm(_) ->
false.
diff --git a/src/ranch_conns_sup.erl b/src/ranch_conns_sup.erl
index d5f5200..fcf5927 100644
--- a/src/ranch_conns_sup.erl
+++ b/src/ranch_conns_sup.erl
@@ -307,7 +307,10 @@ schedule_activate_alarm(_, _) ->
get_alarms(#{alarms := Alarms}) when is_map(Alarms) ->
maps:fold(
fun
- (Name, Opts = #{type := num_connections}, Acc) -> Acc#{Name => {Opts, undefined}};
+ (Name, Opts = #{type := num_connections, cooldown := _}, Acc) ->
+ Acc#{Name => {Opts, undefined}};
+ (Name, Opts = #{type := num_connections}, Acc) ->
+ Acc#{Name => {Opts#{cooldown => 5000}, undefined}};
(_, _, Acc) -> Acc
end,
#{},