blob: 8be57dfb41e162929e3f41ccce24ca7a718f011c [file] [log] [blame]
Christopher Piroefd5eec2007-10-02 01:33:37 +00001%%% Copyright (c) 2007- Facebook
2%%% Distributed under the Thrift Software License
Christopher Pirode11d852007-11-18 02:10:20 +00003%%%
Christopher Piroefd5eec2007-10-02 01:33:37 +00004%%% 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
17start_link(Port, Handler, Processor) ->
18 Args = [Port, Handler, Processor],
19 supervisor:start_link({local, ?SERVER}, ?MODULE, Args).
20
21init([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 Pirode11d852007-11-18 02:10:20 +000032 permanent, 2000, worker, ThriftModules},
Christopher Piroefd5eec2007-10-02 01:33:37 +000033
34 {ok, {{one_for_one, 10, 1}, [ThriftServer]}}.
35
36thrift_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 Piro215ba5c2008-02-20 08:19:38 +000039 case ?R0(Pid, effectful_serve) of
40 ok ->
41 ok;
42 {error, eaddrinuse} ->
43 exit(eaddrinuse)
44 end,
Christopher Piroefd5eec2007-10-02 01:33:37 +000045 {ok, Pid}.