Be more lenient when closing things down.
[etorrent.git] / lib / etorrent-1.0 / src / etorrent_t_peer_sup.erl
blob56bd6dcb4fc183d6f5031ef76f098adff9f34a06
1 %%%-------------------------------------------------------------------
2 %%% File : etorrent_t_peer_sup.erl
3 %%% Author : Jesper Louis Andersen <>
4 %%% Description : Supervisor for a peer connection.
5 %%%
6 %%% Created : 10 Jul 2008 by Jesper Louis Andersen <>
7 %%%-------------------------------------------------------------------
8 -module(etorrent_t_peer_sup).
10 -behaviour(supervisor).
12 %% API
13 -export([start_link/5, add_sender/5]).
15 %% Supervisor callbacks
16 -export([init/1]).
18 -define(SERVER, ?MODULE).
20 %%====================================================================
21 %% API functions
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,
29 InfoHash,
30 FilesystemPid,
31 GroupPid,
32 Id]).
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]}} |
45 %% ignore |
46 %% {error, Reason}
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
50 %% specifications.
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 %%====================================================================
59 %% Internal functions
60 %%====================================================================