diff options
author | Anders Svensson <[email protected]> | 2016-03-05 16:18:52 +0100 |
---|---|---|
committer | Anders Svensson <[email protected]> | 2016-03-13 07:10:11 +0100 |
commit | 2ffb288d8daeb72c27c5cead30ce779682bdd8b0 (patch) | |
tree | e7b2bb7a2c4b4d2243793050df29ce23cb5f6137 /lib/diameter/src/base/diameter_traffic.erl | |
parent | e7b286c95531595daa26b09edffbf2f081c5455a (diff) | |
download | otp-2ffb288d8daeb72c27c5cead30ce779682bdd8b0.tar.gz otp-2ffb288d8daeb72c27c5cead30ce779682bdd8b0.tar.bz2 otp-2ffb288d8daeb72c27c5cead30ce779682bdd8b0.zip |
Let throttling callback return a notification pid
In addition to returning ok or {timeout, Tmo}, let a throttling callback
for message reception return a pid(), which is then notified if the
message in question is either discarded or results in a request process.
Notification is by way of messages of the form
{diameter, discard | {request, pid()}}
where the pid is that of a request process resulting from the received
message. This allows the notification process to keep track of the
maximum number of request processes a peer connection can have given
rise to.
Diffstat (limited to 'lib/diameter/src/base/diameter_traffic.erl')
-rw-r--r-- | lib/diameter/src/base/diameter_traffic.erl | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/lib/diameter/src/base/diameter_traffic.erl b/lib/diameter/src/base/diameter_traffic.erl index 5d39c08213..fba4d3736b 100644 --- a/lib/diameter/src/base/diameter_traffic.erl +++ b/lib/diameter/src/base/diameter_traffic.erl @@ -232,7 +232,20 @@ pending(TPids) -> %% used to come through the service process but this avoids that %% becoming a bottleneck. -receive_message(TPid, Pkt, Dict0, RecvData) +receive_message(TPid, {Pkt, NPid}, Dict0, RecvData) -> + NPid ! {diameter, case incoming(TPid, Pkt, Dict0, RecvData) of + Pid when is_pid(Pid) -> + {request, Pid}; + _ -> + discard + end}; + +receive_message(TPid, Pkt, Dict0, RecvData) -> + incoming(TPid, Pkt, Dict0, RecvData). + +%% incoming/4 + +incoming(TPid, Pkt, Dict0, RecvData) when is_pid(TPid) -> #diameter_packet{header = #diameter_header{is_request = R}} = Pkt, recv(R, @@ -246,7 +259,13 @@ receive_message(TPid, Pkt, Dict0, RecvData) %% Incoming request ... recv(true, false, TPid, Pkt, Dict0, T) -> - spawn_request(TPid, Pkt, Dict0, T); + try + spawn_request(TPid, Pkt, Dict0, T) + catch + error: system_limit = E -> %% discard + ?LOG(error, E), + {error, E} + end; %% ... answer to known request ... recv(false, #request{ref = Ref, handler = Pid} = Req, _, Pkt, Dict0, _) -> @@ -275,12 +294,7 @@ spawn_request(TPid, Pkt, Dict0, RecvData) -> spawn_request(TPid, Pkt, Dict0, ?DEFAULT_SPAWN_OPTS, RecvData). spawn_request(TPid, Pkt, Dict0, Opts, RecvData) -> - try - spawn_opt(fun() -> recv_request(TPid, Pkt, Dict0, RecvData) end, Opts) - catch - error: system_limit = E -> %% discard - ?LOG(error, E) - end. + spawn_opt(fun() -> recv_request(TPid, Pkt, Dict0, RecvData) end, Opts). %% --------------------------------------------------------------------------- %% recv_request/4 |