PageRenderTime 27ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/src/cowboy_acceptors_sup.erl

http://github.com/extend/cowboy
Erlang | 43 lines | 21 code | 6 blank | 16 comment | 1 complexity | 4c4348df6f1c0a49c5ef868b19d20ef6 MD5 | raw file
Possible License(s): 0BSD
  1. %% Copyright (c) 2011, Lo誰c Hoguin <essen@dev-extend.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(cowboy_acceptors_sup).
  16. -behaviour(supervisor).
  17. -export([start_link/7]). %% API.
  18. -export([init/1]). %% supervisor.
  19. %% API.
  20. -spec start_link(non_neg_integer(), module(), any(),
  21. module(), any(), pid(), pid()) -> {ok, pid()}.
  22. start_link(NbAcceptors, Transport, TransOpts,
  23. Protocol, ProtoOpts, ListenerPid, ReqsPid) ->
  24. supervisor:start_link(?MODULE, [NbAcceptors, Transport, TransOpts,
  25. Protocol, ProtoOpts, ListenerPid, ReqsPid]).
  26. %% supervisor.
  27. -spec init(list()) -> {ok, {{one_for_one, 10, 10}, list()}}.
  28. init([NbAcceptors, Transport, TransOpts,
  29. Protocol, ProtoOpts, ListenerPid, ReqsPid]) ->
  30. {ok, LSocket} = Transport:listen(TransOpts),
  31. MaxConns = proplists:get_value(max_connections, TransOpts, 1024),
  32. Procs = [{{acceptor, self(), N}, {cowboy_acceptor, start_link, [
  33. LSocket, Transport, Protocol, ProtoOpts,
  34. MaxConns, ListenerPid, ReqsPid
  35. ]}, permanent, brutal_kill, worker, []}
  36. || N <- lists:seq(1, NbAcceptors)],
  37. {ok, {{one_for_one, 10, 10}, Procs}}.