Christopher Piro | efd5eec | 2007-10-02 01:33:37 +0000 | [diff] [blame] | 1 | %%% Copyright (c) 2007- Facebook |
| 2 | %%% Distributed under the Thrift Software License |
Christopher Piro | de11d85 | 2007-11-18 02:10:20 +0000 | [diff] [blame] | 3 | %%% |
Christopher Piro | efd5eec | 2007-10-02 01:33:37 +0000 | [diff] [blame] | 4 | %%% See accompanying file LICENSE or visit the Thrift site at: |
| 5 | %%% http://developers.facebook.com/thrift/ |
| 6 | |
| 7 | -module(thrift_sup). |
| 8 | |
| 9 | -behaviour(supervisor). |
| 10 | |
| 11 | -include("thrift.hrl"). |
| 12 | |
| 13 | -export([start_link/3, init/1, thrift_start_link/7]). |
| 14 | |
| 15 | -define(SERVER, ?MODULE). |
| 16 | |
| 17 | start_link(Port, Handler, Processor) -> |
| 18 | Args = [Port, Handler, Processor], |
| 19 | supervisor:start_link({local, ?SERVER}, ?MODULE, Args). |
| 20 | |
| 21 | init([Port, Handler, Processor]) -> |
| 22 | TF = tBufferedTransportFactory, |
| 23 | PF = tBinaryProtocolFactory, |
| 24 | ST = tErlAcceptor, |
| 25 | SF = tErlServer, |
| 26 | |
| 27 | ThriftModules = [TF, PF, ST, SF], |
| 28 | |
| 29 | Args = [SF, Port, Handler, Processor, ST, TF, PF], |
| 30 | |
| 31 | ThriftServer = {thrift_server, {?MODULE, thrift_start_link, Args}, |
Christopher Piro | de11d85 | 2007-11-18 02:10:20 +0000 | [diff] [blame] | 32 | permanent, 2000, worker, ThriftModules}, |
Christopher Piro | efd5eec | 2007-10-02 01:33:37 +0000 | [diff] [blame] | 33 | |
| 34 | {ok, {{one_for_one, 10, 1}, [ThriftServer]}}. |
| 35 | |
| 36 | thrift_start_link(SF = tErlServer, Port, Hnd, Pr, ST, TF, PF) -> |
| 37 | Args = [Port, Hnd, Pr, ST, TF:new(), PF:new()], |
| 38 | Pid = oop:start_new(SF, Args), |
Christopher Piro | 215ba5c | 2008-02-20 08:19:38 +0000 | [diff] [blame] | 39 | case ?R0(Pid, effectful_serve) of |
| 40 | ok -> |
| 41 | ok; |
| 42 | {error, eaddrinuse} -> |
| 43 | exit(eaddrinuse) |
| 44 | end, |
Christopher Piro | efd5eec | 2007-10-02 01:33:37 +0000 | [diff] [blame] | 45 | {ok, Pid}. |