Handle HAVE_ALL and HAVE_NONE. Cleanup the BITFIELD message.
[etorrent.git] / lib / etorrent-1.0 / src / etorrent_acceptor_sup.erl
blobad6db149ac43090b2393c61d1c105644cc947c38
1 %%%-------------------------------------------------------------------
2 %%% File : etorrent_acceptor_sup.erl
3 %%% Author : Jesper Louis Andersen <>
4 %%% Description : Supervise a set of acceptor processes.
5 %%%
6 %%% Created : 25 Aug 2007 by Jesper Louis Andersen <>
7 %%%-------------------------------------------------------------------
8 -module(etorrent_acceptor_sup).
10 -behaviour(supervisor).
12 %% API
13 -export([start_link/1]).
15 %% Supervisor callbacks
16 -export([init/1]).
18 -define(DEFAULT_AMOUNT_OF_ACCEPTORS, 5).
19 -define(SERVER, ?MODULE).
21 %%====================================================================
22 %% API functions
23 %%====================================================================
24 %%--------------------------------------------------------------------
25 %% Function: start_link(PeerId) -> {ok,Pid} | ignore | {error,Error}
26 %% Description: Starts the supervisor
27 %%--------------------------------------------------------------------
28 start_link(PeerId) ->
29 supervisor:start_link({local, ?SERVER}, ?MODULE, [PeerId]).
31 %%====================================================================
32 %% Supervisor callbacks
33 %%====================================================================
34 %%--------------------------------------------------------------------
35 %% Func: init(Args) -> {ok, {SupFlags, [ChildSpec]}} |
36 %% ignore |
37 %% {error, Reason}
38 %% Description: Whenever a supervisor is started using
39 %% supervisor:start_link/[2,3], this function is called by the new process
40 %% to find out about restart strategy, maximum restart frequency and child
41 %% specifications.
42 %%--------------------------------------------------------------------
43 init([PeerId]) ->
44 Children = build_children(PeerId, ?DEFAULT_AMOUNT_OF_ACCEPTORS),
45 {ok, {{one_for_one, 1, 60}, Children}}.
47 %%====================================================================
48 %% Internal functions
49 %%====================================================================
51 build_children(_PeerId, 0) -> [];
52 build_children(PeerId, N) ->
53 Id = {acceptor, N},
54 ChildSpec = {Id,
55 {etorrent_acceptor, start_link, [PeerId]},
56 permanent, 2000, worker, [etorrent_acceptor]},
57 [ChildSpec | build_children(PeerId, N-1)].