aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2016-06-12 09:09:38 +0200
committerAnders Svensson <[email protected]>2016-06-12 09:09:38 +0200
commitbddd9a9dd2f784eb570795b0f8ecd25d7ed93378 (patch)
tree42045524ac35c6c0f8c546026bffe54ee10bdcb1
parentf027ac4d0f1d522e3b3d5c4695baf42a5cdd5330 (diff)
parent010925dd108b560ed86d9e0d8f48beefd677728e (diff)
downloadotp-bddd9a9dd2f784eb570795b0f8ecd25d7ed93378.tar.gz
otp-bddd9a9dd2f784eb570795b0f8ecd25d7ed93378.tar.bz2
otp-bddd9a9dd2f784eb570795b0f8ecd25d7ed93378.zip
Merge branch 'anders/diameter/19/listen/OTP-13611'
* anders/diameter/19/listen/OTP-13611: Fix testsuite match blunder Remove unnecessary no_auto_import Redo transport config server as a gen_server
-rw-r--r--lib/diameter/src/base/diameter_config.erl67
-rw-r--r--lib/diameter/test/diameter_gen_sctp_SUITE.erl6
2 files changed, 30 insertions, 43 deletions
diff --git a/lib/diameter/src/base/diameter_config.erl b/lib/diameter/src/base/diameter_config.erl
index 73b828536b..fdbbd412a1 100644
--- a/lib/diameter/src/base/diameter_config.erl
+++ b/lib/diameter/src/base/diameter_config.erl
@@ -38,8 +38,6 @@
-module(diameter_config).
-behaviour(gen_server).
--compile({no_auto_import, [monitor/2]}).
-
-export([start_service/2,
stop_service/1,
add_transport/2,
@@ -61,8 +59,7 @@
code_change/3]).
%% callbacks
--export([sync/1, %% diameter_sync requests
- remove/0]). %% transport server termination
+-export([sync/1]). %% diameter_sync requests
%% debug
-export([state/0,
@@ -72,7 +69,8 @@
-include("diameter_internal.hrl").
%% Server state.
--record(state, {id = diameter_lib:now()}).
+-record(state, {id = diameter_lib:now(),
+ role :: server | transport}).
%% Registered name of the server.
-define(SERVER, ?MODULE).
@@ -292,7 +290,7 @@ uptime() ->
%% ?SERVER start.
init([]) ->
- {ok, #state{}};
+ {ok, #state{role = server}};
%% Child start as a consequence of add_transport.
init({SvcName, Type, Opts}) ->
@@ -302,31 +300,16 @@ init({SvcName, Type, Opts}) ->
?FAILURE(Reason) -> {error, Reason}
end,
proc_lib:init_ack({ok, self(), Res}),
- sleep(Res).
+ loop(Res).
-%% sleep/1
+%% loop/1
-sleep({ok, _}) ->
- sleep();
+loop({ok, _}) ->
+ gen_server:enter_loop(?MODULE, [], #state{role = transport});
-sleep({error, _}) ->
+loop({error, _}) ->
ok. %% die
-%% sleep/0
-
-sleep() ->
- proc_lib:hibernate(?MODULE, remove, []).
-
-%% remove/0
-
-remove() ->
- receive
- {?MODULE, stop} ->
- ok;
- _ ->
- sleep()
- end.
-
%%% ----------------------------------------------------------
%%% # handle_call/2
%%% ----------------------------------------------------------
@@ -334,8 +317,8 @@ remove() ->
handle_call(state, _, State) ->
{reply, State, State};
-handle_call(uptime, _, #state{id = Time} = State) ->
- {reply, diameter_lib:now_diff(Time), State};
+handle_call(uptime, _, #state{id = Time} = S) ->
+ {reply, diameter_lib:now_diff(Time), S};
handle_call(Req, From, State) ->
?UNEXPECTED([Req, From]),
@@ -354,30 +337,34 @@ handle_cast(Msg, State) ->
%%% # handle_info/2
%%% ----------------------------------------------------------
+%% remove_transport is telling published child to die.
+handle_info(stop, #state{role = transport} = S) ->
+ {stop, normal, S};
+
%% A service process has died. This is most likely a consequence of
%% stop_service, in which case the restart will find no config for the
%% service and do nothing. The entry keyed on the monitor ref is only
%% removed as a result of the 'DOWN' notification however.
-handle_info({'DOWN', MRef, process, _, Reason}, State) ->
+handle_info({'DOWN', MRef, process, _, Reason}, #state{role = server} = S) ->
[#monitor{service = SvcName} = T] = select([{#monitor{mref = MRef,
_ = '_'},
[],
['$_']}]),
queue_restart(Reason, SvcName),
delete_object(T),
- {noreply, State};
+ {noreply, S};
-handle_info({monitor, SvcName, Pid}, State) ->
- monitor(Pid, SvcName),
- {noreply, State};
+handle_info({monitor, SvcName, Pid}, #state{role = server} = S) ->
+ insert_monitor(Pid, SvcName),
+ {noreply, S};
-handle_info({restart, SvcName}, State) ->
+handle_info({restart, SvcName}, #state{role = server} = S) ->
restart(SvcName),
- {noreply, State};
+ {noreply, S};
-handle_info(restart, State) ->
+handle_info(restart, #state{role = server} = S) ->
restart(),
- {noreply, State};
+ {noreply, S};
handle_info(Info, State) ->
?UNEXPECTED([Info]),
@@ -491,8 +478,8 @@ startmon(SvcName, {ok, Pid}) ->
startmon(_, {error, _}) ->
ok.
-monitor(Pid, SvcName) ->
- MRef = erlang:monitor(process, Pid),
+insert_monitor(Pid, SvcName) ->
+ MRef = monitor(process, Pid),
insert(#monitor{mref = MRef, service = SvcName}).
%% queue_restart/2
@@ -667,7 +654,7 @@ remove(SvcName, L) ->
stop_child(Ref) ->
case diameter_reg:match(?TRANSPORT_KEY(Ref)) of
[{_, Pid}] -> %% tell the transport-specific child to die
- Pid ! {?MODULE, stop};
+ Pid ! stop;
[] -> %% already removed/dead
ok
end.
diff --git a/lib/diameter/test/diameter_gen_sctp_SUITE.erl b/lib/diameter/test/diameter_gen_sctp_SUITE.erl
index cbd7fc8ec5..79db39ca45 100644
--- a/lib/diameter/test/diameter_gen_sctp_SUITE.erl
+++ b/lib/diameter/test/diameter_gen_sctp_SUITE.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.
@@ -365,8 +365,8 @@ open(Opts) ->
assoc(Sock) ->
receive
- ?SCTP(Sock, {[], #sctp_assoc_change{state = S,
- assoc_id = Id}}) ->
+ ?SCTP(Sock, {_, #sctp_assoc_change{state = S,
+ assoc_id = Id}}) ->
comm_up = S, %% assert
Id
end.