From 5f6399fb9f5d1552bb0050b18e1c9a9085d8b5db Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Tue, 10 Feb 2015 18:04:24 +0100 Subject: 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. --- lib/diameter/src/transport/diameter_sctp.erl | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'lib/diameter/src') 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 %% --------------------------------------------------------------------------- -- cgit v1.2.3