From b5e35d8da2c83f176071730b0e7ce7daa7866f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 8 Mar 2016 07:15:34 +0100 Subject: Reorder and comment API functions Move all functions meant to be called from other modules before the internal functions. Comment them to make it clearer what their purpose are. --- lib/kernel/src/erl_distribution.erl | 54 ++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/lib/kernel/src/erl_distribution.erl b/lib/kernel/src/erl_distribution.erl index 99db7a8bf0..e97c9db81f 100644 --- a/lib/kernel/src/erl_distribution.erl +++ b/lib/kernel/src/erl_distribution.erl @@ -25,6 +25,8 @@ -define(DBG,erlang:display([?MODULE,?LINE])). +%% Called during system start-up. + start_link() -> case catch start_p() of {ok,Args} -> @@ -33,8 +35,38 @@ start_link() -> ignore end. +%% Called from net_kernel:start/1 to start distribution after the +%% system has already started. + +start(Args) -> + C = {net_sup_dynamic, {?MODULE,start_link,[Args]}, permanent, + 1000, supervisor, [erl_distribution]}, + supervisor:start_child(kernel_sup, C). + +%% Stop distribution. + +stop() -> + case supervisor:terminate_child(kernel_sup, net_sup_dynamic) of + ok -> + supervisor:delete_child(kernel_sup, net_sup_dynamic); + Error -> + case whereis(net_sup) of + Pid when is_pid(Pid) -> + %% Dist. started through -sname | -name flags + {error, not_allowed}; + _ -> + Error + end + end. + +%%% +%%% Internal helper functions. +%%% + +%% Helper start function. + start_link(Args) -> - supervisor:start_link({local,net_sup},erl_distribution,Args). + supervisor:start_link({local,net_sup}, ?MODULE, Args). init(NetArgs) -> Epmd = @@ -84,23 +116,3 @@ ticktime() -> _ -> [] end. - -start(Args) -> - C = {net_sup_dynamic, {erl_distribution, start_link, [Args]}, permanent, - 1000, supervisor, [erl_distribution]}, - supervisor:start_child(kernel_sup, C). - -stop() -> - case supervisor:terminate_child(kernel_sup, net_sup_dynamic) of - ok -> - supervisor:delete_child(kernel_sup, net_sup_dynamic); - Error -> - case whereis(net_sup) of - Pid when is_pid(Pid) -> - %% Dist. started through -sname | -name flags - {error, not_allowed}; - _ -> - Error - end - end. - -- cgit v1.2.3