aboutsummaryrefslogtreecommitdiffstats
path: root/lib/diameter
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2017-04-29 09:44:54 +0200
committerAnders Svensson <[email protected]>2017-06-13 13:50:06 +0200
commit77052371aacf68ad4698f75d5a06f7cb2420a66c (patch)
treea9e2244adc2e4bffcc6b726119f0c03a6566dc68 /lib/diameter
parent931c9f8f366309e4b43ea29552240b350b3ac22c (diff)
downloadotp-77052371aacf68ad4698f75d5a06f7cb2420a66c.tar.gz
otp-77052371aacf68ad4698f75d5a06f7cb2420a66c.tar.bz2
otp-77052371aacf68ad4698f75d5a06f7cb2420a66c.zip
Avoid recreating records
In this case the diameter_packet of an answer message for encode. The record itself could be avoided, but that requires a new interface in diameter_codec, probably for little gain.
Diffstat (limited to 'lib/diameter')
-rw-r--r--lib/diameter/src/base/diameter_traffic.erl54
1 files changed, 31 insertions, 23 deletions
diff --git a/lib/diameter/src/base/diameter_traffic.erl b/lib/diameter/src/base/diameter_traffic.erl
index c1bced4e3b..9ebb027c4f 100644
--- a/lib/diameter/src/base/diameter_traffic.erl
+++ b/lib/diameter/src/base/diameter_traffic.erl
@@ -783,31 +783,20 @@ eval_packet(Pkt, Fs) ->
%% the errors field has been explicitly set. Unfortunately, the
%% default value is the empty list rather than 'undefined' so use the
%% atom 'false' for "set nothing". (This is historical and changing
-%% the default value would require modules including diameter.hrl to
-%% be recompiled.)
-make_answer_packet(#diameter_packet{errors = []}
- = Pkt,
- #diameter_packet{errors = [_|_] = Es}
- = ReqPkt) ->
- make_answer_packet(Pkt#diameter_packet{errors = Es}, ReqPkt);
-
-%% A reply message clears the R and T flags and retains the P flag.
-%% The E flag will be set at encode. 6.2 of 3588 requires the same P
-%% flag on an answer as on the request. A #diameter_packet{} returned
-%% from a handle_request callback can circumvent this by setting its
-%% own header values.
+%% the default value would impact anyone expecting relying on the old
+%% default.)
make_answer_packet(#diameter_packet{header = Hdr,
msg = Msg,
errors = Es,
transport_data = TD},
- #diameter_packet{header = ReqHdr}) ->
- Hdr0 = ReqHdr#diameter_header{version = ?DIAMETER_VERSION,
- is_request = false,
- is_error = undefined,
- is_retransmitted = false},
- #diameter_packet{header = fold_record(Hdr0, Hdr),
+ #diameter_packet{header = Hdr0,
+ errors = Es0}) ->
+ #diameter_packet{header = make_answer_header(Hdr0, Hdr),
msg = Msg,
- errors = Es,
+ errors = case Es0 of
+ [_|_] when [] == Es -> Es0;
+ _ -> Es
+ end,
transport_data = TD};
%% Binaries and header/avp lists are sent as-is.
@@ -820,9 +809,28 @@ make_answer_packet([#diameter_header{} | _] = Msg,
#diameter_packet{msg = Msg,
transport_data = TD};
-%% Otherwise, preserve transport_data.
-make_answer_packet(Msg, #diameter_packet{transport_data = TD} = Pkt) ->
- make_answer_packet(#diameter_packet{msg = Msg, transport_data = TD}, Pkt).
+%% Otherwise, only reset the header.
+make_answer_packet(Msg, #diameter_packet{header = Hdr,
+ errors = Es,
+ transport_data = TD}) ->
+ #diameter_packet{header = make_answer_header(Hdr, undefined),
+ msg = Msg,
+ errors = Es,
+ transport_data = TD}.
+
+%% make_answer_header/2
+
+%% A reply message clears the R and T flags and retains the P flag.
+%% The E flag will be set at encode. 6.2 of 3588 requires the same P
+%% flag on an answer as on the request. A #diameter_packet{} returned
+%% from a handle_request callback can circumvent this by setting its
+%% own header values.
+make_answer_header(ReqHdr, Hdr) ->
+ Hdr0 = ReqHdr#diameter_header{version = ?DIAMETER_VERSION,
+ is_request = false,
+ is_error = undefined,
+ is_retransmitted = false},
+ fold_record(Hdr0, Hdr).
%% Reply as name and tuple list ...
set([_|_] = Ans, Avps, _) ->