ranch_conns_sup.erl 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. %% Copyright (c) 2011-2012, 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. %% @private
  15. -module(ranch_conns_sup).
  16. -behaviour(supervisor).
  17. %% API.
  18. -export([start_link/1]).
  19. -export([start_protocol/5]).
  20. %% supervisor.
  21. -export([init/1]).
  22. %% API.
  23. -spec start_link(any()) -> {ok, pid()}.
  24. start_link(Ref) ->
  25. supervisor:start_link(?MODULE, Ref).
  26. -spec start_protocol(pid(), inet:socket(), module(), module(), any())
  27. -> {ok, pid()}.
  28. start_protocol(ListenerPid, Socket, Transport, Protocol, Opts) ->
  29. Protocol:start_link(ListenerPid, Socket, Transport, Opts).
  30. %% supervisor.
  31. init(Ref) ->
  32. ok = ranch_server:set_connections_sup(Ref, self()),
  33. {ok, {{simple_one_for_one, 0, 1}, [{?MODULE, {?MODULE, start_protocol, []},
  34. temporary, brutal_kill, worker, [?MODULE]}]}}.