aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2015-02-10 18:04:24 +0100
committerAnders Svensson <[email protected]>2015-02-20 02:23:39 +0100
commit5f6399fb9f5d1552bb0050b18e1c9a9085d8b5db (patch)
treeb644959b881ffc316000871e2020b61dbd581ed6 /lib
parent5180aeb954036f532835958dda8eab8fe456494b (diff)
downloadotp-5f6399fb9f5d1552bb0050b18e1c9a9085d8b5db.tar.gz
otp-5f6399fb9f5d1552bb0050b18e1c9a9085d8b5db.tar.bz2
otp-5f6399fb9f5d1552bb0050b18e1c9a9085d8b5db.zip
Be backwards compatible with diameter_sctp listener state
Commit 24993fc2 modified the state even in the case that the new pool_size option the change was introduced to support was not used. Doing so made downgrade impossible since old code would not be prepared for the modified state. Retain a compatible state, so that simple code replacement is enough.
Diffstat (limited to 'lib')
-rw-r--r--lib/diameter/src/transport/diameter_sctp.erl23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/diameter/src/transport/diameter_sctp.erl b/lib/diameter/src/transport/diameter_sctp.erl
index 4483e06737..66cffa41c0 100644
--- a/lib/diameter/src/transport/diameter_sctp.erl
+++ b/lib/diameter/src/transport/diameter_sctp.erl
@@ -123,7 +123,8 @@
%% queue or spawned and placed in the first queue. Thus, there are
%% only elements in one queue at a time, so share an ets table queue
%% and tag it with a positive length if it contains the first queue, a
-%% negative length if it contains the second queue.
+%% negative length if it contains the second queue. The case -1 is
+%% handled differently for backwards compatibility reasons.
%% ---------------------------------------------------------------------------
%% # start/3
@@ -373,8 +374,8 @@ handle_call({{accept, Ref}, Pid}, _, #listener{ref = Ref,
count = K}
= S) ->
TPid = accept(Ref, Pid, S),
- {reply, {ok, TPid}, S#listener{pending = {N-1,Q},
- count = K+1}};
+ {reply, {ok, TPid}, downgrade(S#listener{pending = {N-1,Q},
+ count = K+1})};
handle_call(_, _, State) ->
{reply, nok, State}.
@@ -398,7 +399,7 @@ handle_info(T, #listener{pending = L} = S)
handle_info(T, upgrade(S));
handle_info(T, #listener{} = S) ->
- {noreply, #listener{} = l(T,S)}.
+ {noreply, downgrade(#listener{} = l(T,S))}.
%% upgrade/1
@@ -420,6 +421,20 @@ upgrade(#listener{pending = [TPid | {0,Q}]} = S) ->
%% absolute value of the first element of the 2-tuple is the queue
%% length, the sign says which queue it is.
+%% downgrade/1
+%%
+%% Revert to the pre-pool_size representation when possible, for
+%% backwards compatibility in the case that the pool_size option
+%% hasn't been used.
+
+downgrade(#listener{pending = {-1,Q}} = S) ->
+ TPid = ets:first(Q),
+ ets:delete(Q, TPid),
+ S#listener{pending = [TPid | {0,Q}]};
+
+downgrade(S) ->
+ S.
+
%% ---------------------------------------------------------------------------
%% # code_change/3
%% ---------------------------------------------------------------------------