aboutsummaryrefslogtreecommitdiffstats
path: root/src/ranch.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/ranch.erl')
-rw-r--r--src/ranch.erl28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/ranch.erl b/src/ranch.erl
index f36c145..576f122 100644
--- a/src/ranch.erl
+++ b/src/ranch.erl
@@ -55,7 +55,17 @@
-type opts() :: any() | transport_opts(any()).
-export_type([opts/0]).
+-type alarm(Type, Callback) :: #{
+ type := Type,
+ callback := Callback,
+ treshold := non_neg_integer(),
+ cooldown := non_neg_integer()
+}.
+
+-type alarm_num_connections() :: alarm(num_connections, fun((ref(), term(), pid(), [pid()]) -> any())).
+
-type transport_opts(SocketOpts) :: #{
+ alarms => #{term() => alarm_num_connections()},
connection_type => worker | supervisor,
handshake_timeout => timeout(),
logger => module(),
@@ -123,6 +133,16 @@ validate_transport_opt(max_connections, infinity, _) ->
true;
validate_transport_opt(max_connections, Value, _) ->
is_integer(Value) andalso Value >= 0;
+validate_transport_opt(alarms, Alarms, _) ->
+ maps:fold(
+ fun
+ (_, Opts, true) ->
+ validate_alarm(Opts);
+ (_, _, false) ->
+ false
+ end,
+ true,
+ Alarms);
validate_transport_opt(logger, Value, _) ->
is_atom(Value);
validate_transport_opt(num_acceptors, Value, _) ->
@@ -145,6 +165,14 @@ validate_transport_opt(socket_opts, _, _) ->
validate_transport_opt(_, _, _) ->
false.
+validate_alarm(#{type := num_connections, treshold := Treshold,
+ callback := Callback, cooldown := Cooldown}) ->
+ is_integer(Treshold) andalso Treshold >= 0
+ andalso is_integer(Cooldown) andalso Cooldown >= 0
+ andalso is_function(Callback, 4);
+validate_alarm(_) ->
+ false.
+
maybe_started({error, {{shutdown,
{failed_to_start_child, ranch_acceptors_sup,
{listen_error, _, Reason}}}, _}} = Error) ->