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:
parent
576d246ccd
commit
536fdd5f50
@ -33,6 +33,7 @@ start() ->
|
|||||||
%% @doc Listen for connections.
|
%% @doc Listen for connections.
|
||||||
|
|
||||||
listen() ->
|
listen() ->
|
||||||
|
process_flag(trap_exit, true),
|
||||||
{ok, LSocket} = ssl:listen(?GAME_PORT, ?GAME_LISTEN_OPTIONS),
|
{ok, LSocket} = ssl:listen(?GAME_PORT, ?GAME_LISTEN_OPTIONS),
|
||||||
?MODULE:accept(LSocket).
|
?MODULE:accept(LSocket).
|
||||||
|
|
||||||
@ -42,10 +43,15 @@ accept(LSocket) ->
|
|||||||
case ssl:transport_accept(LSocket, 5000) of
|
case ssl:transport_accept(LSocket, 5000) of
|
||||||
{ok, CSocket} ->
|
{ok, CSocket} ->
|
||||||
ssl:ssl_accept(CSocket),
|
ssl:ssl_accept(CSocket),
|
||||||
log(0, "hello (new connection)"),
|
try
|
||||||
egs_proto:send_hello(CSocket),
|
log(0, "hello (new connection)"),
|
||||||
PID = spawn_link(?MODULE, process, [CSocket, 0]),
|
egs_proto:send_hello(CSocket),
|
||||||
ssl:controlling_process(CSocket, PID);
|
Pid = spawn_link(?MODULE, process, [CSocket, 0]),
|
||||||
|
ssl:controlling_process(CSocket, Pid)
|
||||||
|
catch
|
||||||
|
_:_ ->
|
||||||
|
reload
|
||||||
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
reload
|
reload
|
||||||
end,
|
end,
|
||||||
|
@ -34,6 +34,7 @@ start() ->
|
|||||||
%% @doc Listen for connections.
|
%% @doc Listen for connections.
|
||||||
|
|
||||||
listen(Port, SessionID) ->
|
listen(Port, SessionID) ->
|
||||||
|
process_flag(trap_exit, true),
|
||||||
{ok, LSocket} = ssl:listen(Port, ?LOGIN_LISTEN_OPTIONS),
|
{ok, LSocket} = ssl:listen(Port, ?LOGIN_LISTEN_OPTIONS),
|
||||||
?MODULE:accept(LSocket, SessionID).
|
?MODULE:accept(LSocket, SessionID).
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ start() ->
|
|||||||
%% @doc Listen for connections.
|
%% @doc Listen for connections.
|
||||||
|
|
||||||
listen(Port) ->
|
listen(Port) ->
|
||||||
|
process_flag(trap_exit, true),
|
||||||
{ok, LSocket} = gen_tcp:listen(Port, ?PATCH_LISTEN_OPTIONS),
|
{ok, LSocket} = gen_tcp:listen(Port, ?PATCH_LISTEN_OPTIONS),
|
||||||
?MODULE:accept(LSocket).
|
?MODULE:accept(LSocket).
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user