Erlang: when do you need to do `inets: start ()`?

Which place is right for doing inets:start()?

  • in the module `applicationname_app '?
  • to the applicationname_supsupervisor module?
  • in a child process dependent on a supervisor? \
  • somewhere else?

(I'm still struggling with inets:httpd)

Note : the response cannot be configured to "use boot file".

+3
source share
3 answers

inets is an "stand-alone" Erlang application; inets:start()is just an alias application:start(inets). I think the answer pretty much depends on how you maintain your code.

application, .app inets, (. ). application:start(my_app). . : , : -P

, , , , . , , . , , - :

ensure_app_started(App) ->
  case application:started(App) of
    ok -> ok;
    {error, already_started} -> ok;
    Error -> Error
  end.
+4

, inets :

% Filename: ebin/flamingo.app
{application, flamingo,
  [{vsn, "1.0.0"},
   {modules, [flamingo_app,
              flamingo_sup,
              flamingo]},
   {applications, [kernel,
                   stdlib,
                   inets]},
   {mod, {flamingo_app, []}}
  ]}.

, application:ensure_all_started(flamingo). , inets (.. inets:start()).

( , *.app *.beam ebin/):

$ erl -pa ebin/
Eshell V9.2  (abort with ^G)
1> application:ensure_all_started(flamingo).
{ok,[inets,flamingo]}
0

2019 rebar3 . , , rebar.config, rebar3 . , hackney ( http) rebar.config:

{erl_opts, [debug_info]}.
{deps, [
  {hackney, ".*", {git, "git://github.com/benoitc/hackney.git", {branch, "master"}}}
]}.

{shell, [
  % {config, "config/sys.config"},
    {apps, [http_client]}
]}.

:

../your_app_name$ rebar3 compile

rebar3 hackney application.

, , :

src/your_app_name.app.src

,

{application, http_client,
 [{description, "An OTP application"},
  {vsn, "0.1.0"},
  {registered, []},
  {mod, {http_client_app, []}},
  {applications,
   [kernel,
    stdlib,
    hackney    %%%<=========HERE
   ]},
  {env,[]},
  {modules, []},

  {licenses, ["Apache 2.0"]},
  {links, []}
 ]}.

.app :

_build/default/lib/your_app_name/ebin/your_app_name.app

, :

../your_app_name$ rebar3 shell 

inets erlang, , inets rebar.config ( $ rebar3 compile). inets application :

src/your_app_name.app.src

rebar3 inets ( ), inets , inets , . , inets application, :

$ rebar3 shell
...
...
1> application:start(inets)
{error,{already_started,inets}}

inets inets .

0

Source: https://habr.com/ru/post/1724615/


All Articles