summaryrefslogtreecommitdiff
path: root/lib/diameter/src/base/diameter_config.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/diameter/src/base/diameter_config.erl')
-rw-r--r--lib/diameter/src/base/diameter_config.erl53
1 files changed, 23 insertions, 30 deletions
diff --git a/lib/diameter/src/base/diameter_config.erl b/lib/diameter/src/base/diameter_config.erl
index 495e57e456..733e9105f4 100644
--- a/lib/diameter/src/base/diameter_config.erl
+++ b/lib/diameter/src/base/diameter_config.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2020. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2023. 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.
@@ -291,21 +291,14 @@ init([]) ->
%% Child start as a consequence of add_transport.
init({SvcName, Type, Opts}) ->
- Res = try
- add(SvcName, Type, Opts)
- catch
- ?FAILURE(Reason) -> {error, Reason}
- end,
- proc_lib:init_ack({ok, self(), Res}),
- loop(Res).
-
-%% loop/1
-
-loop({ok, _}) ->
- gen_server:enter_loop(?MODULE, [], #state{role = transport});
-
-loop({error, _}) ->
- ok. %% die
+ try add(SvcName, Type, Opts) of
+ Ref ->
+ proc_lib:init_ack({ok, self(), Ref}),
+ gen_server:enter_loop(?MODULE, [], #state{role = transport})
+ catch
+ ?FAILURE(Reason) ->
+ proc_lib:init_fail({error, Reason}, {exit, normal}) %% die
+ end.
%%% ----------------------------------------------------------
%%% # handle_call/2
@@ -443,8 +436,12 @@ sync({stop_service, SvcName}) ->
%% This is to provide a way for processes to to be notified when the
%% configuration is removed (diameter_reg:subscribe/2).
sync({add, SvcName, Type, Opts}) ->
- {ok, _Pid, Res} = diameter_config_sup:start_child({SvcName, Type, Opts}),
- Res;
+ case diameter_config_sup:start_child({SvcName, Type, Opts}) of
+ {ok, _Pid, Ref} ->
+ {ok, Ref};
+ {error, _} = Res ->
+ Res
+ end;
sync({remove, SvcName, Pred}) ->
Recs = select([{#transport{service = '$1', _ = '_'},
@@ -545,16 +542,12 @@ add(SvcName, Type, Opts0) ->
%% The call to the service returns error if the service isn't
%% started yet, which is harmless. The transport will be started
%% when the service is in that case.
- case start_transport(SvcName, T) of
- ok ->
- insert(#transport{service = SvcName,
- ref = Ref,
- type = Type,
- options = Opts}),
- {ok, Ref};
- {error, _} = No ->
- No
- end.
+ start_transport(SvcName, T),
+ insert(#transport{service = SvcName,
+ ref = Ref,
+ type = Type,
+ options = Opts}),
+ Ref.
transport_opts(Opts) ->
[setopt(transport, T) || T <- Opts].
@@ -751,8 +744,8 @@ start_transport(SvcName, T) ->
ok;
{error, no_service} ->
ok;
- {error, _} = No ->
- No
+ {error, Reason} ->
+ ?THROW(Reason)
end.
%% remove/2