embedded_sup.erl 707 B

12345678910111213141516171819202122232425262728
  1. -module(embedded_sup).
  2. -behaviour(supervisor).
  3. -export([init/1]).
  4. -export([start_link/0]).
  5. -export([stop/1]).
  6. -export([start_listener/6]).
  7. -export([stop_listener/2]).
  8. start_link() ->
  9. supervisor:start_link(?MODULE, []).
  10. stop(SupPid) ->
  11. erlang:exit(SupPid, normal).
  12. init([]) ->
  13. {ok, {{one_for_one, 10, 10}, []}}.
  14. start_listener(SupPid, Ref, Transport, TransOpts, Protocol, ProtoOpts) ->
  15. supervisor:start_child(
  16. SupPid,
  17. ranch:child_spec(Ref, Transport, TransOpts, Protocol, ProtoOpts)
  18. ).
  19. stop_listener(SupPid, Ref) ->
  20. ok = supervisor:terminate_child(SupPid, {ranch_listener_sup, Ref}),
  21. ok = supervisor:delete_child(SupPid, {ranch_listener_sup, Ref}),
  22. ranch_server:cleanup_listener_opts(Ref).