aboutsummaryrefslogtreecommitdiffstats
path: root/lib/diameter/src/transport
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2016-03-05 16:18:52 +0100
committerAnders Svensson <[email protected]>2016-03-13 07:10:11 +0100
commit2ffb288d8daeb72c27c5cead30ce779682bdd8b0 (patch)
treee7b2bb7a2c4b4d2243793050df29ce23cb5f6137 /lib/diameter/src/transport
parente7b286c95531595daa26b09edffbf2f081c5455a (diff)
downloadotp-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/transport')
-rw-r--r--lib/diameter/src/transport/diameter_tcp.erl14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/diameter/src/transport/diameter_tcp.erl b/lib/diameter/src/transport/diameter_tcp.erl
index 91e8d26d36..7f9255c097 100644
--- a/lib/diameter/src/transport/diameter_tcp.erl
+++ b/lib/diameter/src/transport/diameter_tcp.erl
@@ -878,6 +878,20 @@ throttle(ok, #transport{parent = Pid, throttled = Msg} = S) ->
throttle({ok = T, F}, S) ->
throttle(T, S#transport{throttle_cb = F});
+%% Callback says to accept a received message and acknowledged the
+%% returned pid with a {request, Pid} message if a request pid is
+%% spawned, a discard message otherwise. The latter does not mean that
+%% the message was necessarily discarded: it could have been an
+%% answer.
+throttle(NPid, #transport{parent = Pid, throttled = Msg} = S)
+ when is_pid(NPid), is_binary(Msg) ->
+ diameter_peer:recv(Pid, {Msg, NPid}),
+ throttle(S#transport{throttled = true});
+
+throttle({NPid, F}, #transport{throttled = Msg} = S)
+ when is_pid(NPid), is_binary(Msg) ->
+ throttle(NPid, S#transport{throttle_cb = F});
+
%% Callback says to ask again in the specified number of milliseconds.
throttle({timeout, Tmo}, #transport{} = S) ->
erlang:send_after(Tmo, self(), throttle),