ranch_listener_sup.erl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. %% Copyright (c) 2011-2018, Loïc Hoguin <essen@ninenines.eu>
  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_listener_sup).
  15. -behaviour(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. MaxConns = maps:get(max_connections, TransOpts, 1024),
  22. Logger = maps:get(logger, TransOpts, logger),
  23. ranch_server:set_new_listener_opts(Ref, MaxConns, TransOpts, ProtoOpts,
  24. [Ref, Transport, TransOpts, Protocol, ProtoOpts]),
  25. supervisor:start_link(?MODULE, {
  26. Ref, Transport, Protocol, Logger
  27. }).
  28. -spec init({ranch:ref(), module(), module(), module()})
  29. -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
  30. init({Ref, Transport, Protocol, Logger}) ->
  31. ok = ranch_server:set_listener_sup(Ref, self()),
  32. ChildSpecs = [
  33. #{
  34. id => ranch_conns_sup_sup,
  35. start => {ranch_conns_sup_sup, start_link, [Ref, Transport, Protocol, Logger]},
  36. type => supervisor
  37. },
  38. #{
  39. id => ranch_acceptors_sup,
  40. start => {ranch_acceptors_sup, start_link, [Ref, Transport, Logger]},
  41. type => supervisor
  42. }
  43. ],
  44. {ok, {#{strategy => rest_for_one}, ChildSpecs}}.