1 %%%-------------------------------------------------------------------
2 %%% File : etorrent_t_peer_sup.erl
3 %%% Author : Jesper Louis Andersen <>
4 %%% Description : Supervisor for a peer connection.
6 %%% Created : 10 Jul 2008 by Jesper Louis Andersen <>
7 %%%-------------------------------------------------------------------
8 -module(etorrent_t_peer_sup
).
10 -behaviour(supervisor
).
13 -export([start_link
/5, add_sender
/5]).
15 %% Supervisor callbacks
18 -define(SERVER
, ?MODULE
).
20 %%====================================================================
22 %%====================================================================
23 %%--------------------------------------------------------------------
24 %% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
25 %% Description: Starts the supervisor
26 %%--------------------------------------------------------------------
27 start_link(LocalPeerId
, InfoHash
, FilesystemPid
, GroupPid
, Id
) ->
28 supervisor:start_link(?MODULE
, [LocalPeerId
,
34 add_sender(Pid
, Socket
, FileSystemPid
, Id
, RecvPid
) ->
35 Sender
= {sender
, {etorrent_t_peer_send
, start_link
,
36 [Socket
, FileSystemPid
, Id
, RecvPid
]},
37 permanent
, 15000, worker
, [etorrent_t_peer_send
]},
38 supervisor:start_child(Pid
, Sender
).
40 %%====================================================================
41 %% Supervisor callbacks
42 %%====================================================================
43 %%--------------------------------------------------------------------
44 %% Func: init(Args) -> {ok, {SupFlags, [ChildSpec]}} |
47 %% Description: Whenever a supervisor is started using
48 %% supervisor:start_link/[2,3], this function is called by the new process
49 %% to find out about restart strategy, maximum restart frequency and child
51 %%--------------------------------------------------------------------
52 init([LocalPeerId
, InfoHash
, FilesystemPid
, GroupPid
, Id
]) ->
53 Reciever
= {reciever
, {etorrent_t_peer_recv
, start_link
,
54 [LocalPeerId
, InfoHash
, FilesystemPid
, GroupPid
, Id
, self()]},
55 permanent
, 15000, worker
, [etorrent_t_peer_recv
]},
56 {ok
, {{one_for_all
, 0, 1}, [Reciever
]}}.
58 %%====================================================================
60 %%====================================================================