ranch_embedded_sup.erl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. %% Copyright (c) 2019-2021, Jan Uhlig <juhlig@hnc-agency.org>
  2. %%
  3. %% Permission to use, copy, modify, and/or distribute this software for any
  4. %% purpose with or without fee is hereby granted, provided that the above
  5. %% copyright notice and this permission notice appear in all copies.
  6. %%
  7. %% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. %% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. %% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. %% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. %% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. %% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. %% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. -module(ranch_embedded_sup).
  15. -behavior(supervisor).
  16. -export([start_link/5]).
  17. -export([init/1]).
  18. -spec start_link(ranch:ref(), module(), any(), module(), any())
  19. -> {ok, pid()}.
  20. start_link(Ref, Transport, TransOpts, Protocol, ProtoOpts) ->
  21. supervisor:start_link(?MODULE, {Ref, Transport, TransOpts, Protocol, ProtoOpts}).
  22. -spec init({ranch:ref(), module(), any(), module(), any()})
  23. -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
  24. init({Ref, Transport, TransOpts, Protocol, ProtoOpts}) ->
  25. Proxy = #{id => ranch_server_proxy,
  26. start => {ranch_server_proxy, start_link, []},
  27. shutdown => brutal_kill},
  28. Listener = #{id => {ranch_listener_sup, Ref},
  29. start => {ranch_listener_sup, start_link, [Ref, Transport, TransOpts, Protocol, ProtoOpts]},
  30. type => supervisor},
  31. {ok, {#{strategy => rest_for_one}, [Proxy, Listener]}}.