|
@@ -28,23 +28,25 @@
|
|
|
-> {ok, pid()}.
|
|
|
start_link(Ref, NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts) ->
|
|
|
MaxConns = proplists:get_value(max_connections, TransOpts, 1024),
|
|
|
- {ok, SupPid} = supervisor:start_link(?MODULE, []),
|
|
|
- {ok, ListenerPid} = supervisor:start_child(SupPid,
|
|
|
- {ranch_listener, {ranch_listener, start_link,
|
|
|
- [Ref, MaxConns, ProtoOpts]},
|
|
|
- permanent, 5000, worker, [ranch_listener]}),
|
|
|
- ok = ranch_server:insert_listener(Ref, ListenerPid),
|
|
|
- {ok, ConnsPid} = supervisor:start_child(SupPid,
|
|
|
- {ranch_conns_sup, {ranch_conns_sup, start_link, []},
|
|
|
- permanent, 5000, supervisor, [ranch_conns_sup]}),
|
|
|
- {ok, _PoolPid} = supervisor:start_child(SupPid,
|
|
|
- {ranch_acceptors_sup, {ranch_acceptors_sup, start_link, [
|
|
|
- Ref, NbAcceptors, Transport, TransOpts,
|
|
|
- Protocol, ListenerPid, ConnsPid
|
|
|
- ]}, permanent, 5000, supervisor, [ranch_acceptors_sup]}),
|
|
|
- {ok, SupPid}.
|
|
|
+ supervisor:start_link(?MODULE, {
|
|
|
+ Ref, NbAcceptors, MaxConns, Transport, TransOpts, Protocol, ProtoOpts
|
|
|
+ }).
|
|
|
|
|
|
%% supervisor.
|
|
|
|
|
|
-init([]) ->
|
|
|
- {ok, {{one_for_all, 10, 10}, []}}.
|
|
|
+init({Ref, NbAcceptors, MaxConns, Transport, TransOpts, Protocol, ProtoOpts}) ->
|
|
|
+ ChildSpecs = [
|
|
|
+ %% listener
|
|
|
+ {ranch_listener, {ranch_listener, start_link,
|
|
|
+ [Ref, MaxConns, ProtoOpts]},
|
|
|
+ permanent, 5000, worker, [ranch_listener]},
|
|
|
+ %% conns_sup
|
|
|
+ {ranch_conns_sup, {ranch_conns_sup, start_link, [Ref]},
|
|
|
+ permanent, infinity, supervisor, [ranch_conns_sup]},
|
|
|
+ %% acceptors_sup
|
|
|
+ {ranch_acceptors_sup, {ranch_acceptors_sup, start_link,
|
|
|
+ [Ref, NbAcceptors, Transport, TransOpts, Protocol]
|
|
|
+ }, permanent, infinity, supervisor, [ranch_acceptors_sup]}
|
|
|
+ ],
|
|
|
+ {ok, {{rest_for_one, 10, 10}, ChildSpecs}}.
|
|
|
+
|