diff options
author | Anders Svensson <[email protected]> | 2017-08-09 15:20:36 +0200 |
---|---|---|
committer | Anders Svensson <[email protected]> | 2017-08-09 15:20:36 +0200 |
commit | 0c4a4aa70c5bceb9c38ddc939cfa66f16e943550 (patch) | |
tree | ce8eaaadb8a4c06130f13a72b40fb20b2a6409c3 /lib/diameter/examples/code/node.erl | |
parent | 7c8213e3a2da91eca40ae8fcbadae07dcbb9f4c8 (diff) | |
parent | cfb3eeaf354d99d0e62e6cf939b1320c4bdb0840 (diff) | |
download | otp-0c4a4aa70c5bceb9c38ddc939cfa66f16e943550.tar.gz otp-0c4a4aa70c5bceb9c38ddc939cfa66f16e943550.tar.bz2 otp-0c4a4aa70c5bceb9c38ddc939cfa66f16e943550.zip |
Merge branch 'anders/diameter/message_cb/OTP-14486' into maint
* anders/diameter/message_cb/OTP-14486:
Add simple message_cb to example server
Fix inappropriate message callbacks
Diffstat (limited to 'lib/diameter/examples/code/node.erl')
-rw-r--r-- | lib/diameter/examples/code/node.erl | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/diameter/examples/code/node.erl b/lib/diameter/examples/code/node.erl index 246be4194b..fc5830f8e2 100644 --- a/lib/diameter/examples/code/node.erl +++ b/lib/diameter/examples/code/node.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2010-2015. All Rights Reserved. +%% Copyright Ericsson AB 2010-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -30,6 +30,8 @@ connect/2, stop/1]). +-export([message/3]). + -type protocol() :: tcp | sctp. @@ -128,6 +130,8 @@ stop(Name) -> server_opts({T, Addr, Port}) -> [{transport_module, tmod(T)}, {transport_config, [{reuseaddr, true}, + {sender, true}, + {message_cb, [fun ?MODULE:message/3, 0]}, {ip, addr(Addr)}, {port, Port}]}]; @@ -173,3 +177,26 @@ addr(loopback) -> {127,0,0,1}; addr(A) -> A. + +%% --------------------------------------------------------------------------- + +%% message/3 +%% +%% Simple message callback that limits the number of concurrent +%% requests on the peer connection in question. + +%% Incoming request. +message(recv, <<_:32, 1:1, _/bits>> = Bin, N) -> + [Bin, N < 32, fun ?MODULE:message/3, N+1]; + +%% Outgoing request. +message(ack, <<_:32, 1:1, _/bits>>, _) -> + []; + +%% Incoming answer or request discarded. +message(ack, _, N) -> + [N =< 32, fun ?MODULE:message/3, N-1]; + +%% Outgoing message or incoming answer. +message(_, Bin, _) -> + [Bin]. |