Isolate child processes to prevent crashing the whole thing.

Crashes will not propagate anymore so the server shouldn't crash by itself again.
This commit is contained in:
Loïc Hoguin 2010-05-21 09:12:11 +02:00
parent 576d246ccd
commit 536fdd5f50
3 changed files with 12 additions and 4 deletions

View File

@ -33,6 +33,7 @@ start() ->
%% @doc Listen for connections.
listen() ->
process_flag(trap_exit, true),
{ok, LSocket} = ssl:listen(?GAME_PORT, ?GAME_LISTEN_OPTIONS),
?MODULE:accept(LSocket).
@ -42,10 +43,15 @@ accept(LSocket) ->
case ssl:transport_accept(LSocket, 5000) of
{ok, CSocket} ->
ssl:ssl_accept(CSocket),
log(0, "hello (new connection)"),
egs_proto:send_hello(CSocket),
PID = spawn_link(?MODULE, process, [CSocket, 0]),
ssl:controlling_process(CSocket, PID);
try
log(0, "hello (new connection)"),
egs_proto:send_hello(CSocket),
Pid = spawn_link(?MODULE, process, [CSocket, 0]),
ssl:controlling_process(CSocket, Pid)
catch
_:_ ->
reload
end;
_ ->
reload
end,

View File

@ -34,6 +34,7 @@ start() ->
%% @doc Listen for connections.
listen(Port, SessionID) ->
process_flag(trap_exit, true),
{ok, LSocket} = ssl:listen(Port, ?LOGIN_LISTEN_OPTIONS),
?MODULE:accept(LSocket, SessionID).

View File

@ -32,6 +32,7 @@ start() ->
%% @doc Listen for connections.
listen(Port) ->
process_flag(trap_exit, true),
{ok, LSocket} = gen_tcp:listen(Port, ?PATCH_LISTEN_OPTIONS),
?MODULE:accept(LSocket).