主管似乎失敗默默開始孩子......二郎主管未能start_child沒有錯誤simple_one_for_one
這裏的主管
-behaviour(supervisor).
-export([start_socket/0, init/1, start_link/1]).
-define(SSL_OPTIONS, [{active, once},
{backlog, 128},
{reuseaddr, true},
{packet, 0},
{cacertfile, "./ssl_key/server/gd_bundle.crt"},
{certfile, "./ssl_key/server/cert.pem"},
{keyfile, "./ssl_key/server/cert.key"},
{password, "**********"}
]).
start_link(Port) ->
Role = list_to_atom(atom_to_list(?MODULE) ++ lists:flatten(io_lib:format("~B", [Port]))),
supervisor:start_link({local, Role}, ?MODULE, [Port]).
init([Port]) ->
R = ssl:listen(Port, ?SSL_OPTIONS),
LSocket = case R of
{ok, LSock} ->
LSock;
Res ->
io:fwrite("gateway_sup Error: ~p~n", [Res])
end,
spawn_link(fun empty_listeners/0),
ChildSpec = [{socket,
{gateway_serv, start_link, [LSocket]},
temporary, 1000, worker, [gateway_serv]}
],
{ok, {{simple_one_for_one, 3600, 3600},
ChildSpec
}}.
empty_listeners() ->
io:fwrite("---------------------- empty_listeners~n"),
[start_socket() || _ <- lists:seq(1,128)],
ok.
start_socket() ->
io:fwrite("++++++++++++++++++++++ start_socket~n"),
supervisor:start_child(?MODULE, []).
而且gen_server
-module(gateway_serv).
-behaviour(gen_server).
-export([start_link/1, init/1, handle_call/3, handle_cast/2, handle_info/2, code_change/3, terminate/2]).
start_link(LSocket) ->
io:fwrite("#################~n"),
gen_server:start_link(?MODULE, [LSocket], []).
init([LSocket]) ->
io:fwrite("/////////////////~n"),
gen_server:cast(self(), accept),
{ok, #client{listenSocket=LSocket, pid=self()}}.
handle_cast(accept, G = #client{listenSocket=LSocket}) ->
{ok, AcceptSocket} = ssl:transport_accept(LSocket),
gateway_sup:start_socket(),
case ssl:ssl_accept(AcceptSocket, 30000) of
ok ->
timer:send_after(10000, closingSocket),
ssl:setopts(AcceptSocket, [{active, once}, {mode, list}, {packet, 0}]),
{noreply, G#client{listenSocket=none, socket=AcceptSocket}};
{error, _Reason} ->
{stop, normal, G}
end;
handle_cast(_, G) ->
{noreply, G}.
gen_server的start_link/1是appa從來沒有打電話(用io:fwrite檢查)。
不能似乎找出爲什麼......
不,它不會,我們應該看到128行################# – TheSquad
在啓動任何服務器之前,您得到的行打印在主管的init回調中。 – Pascal
@ user601836是的,根據LearnYouSomeErlang,主管,應該開始罰款。 – TheSquad