24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-16 22:05:29 +02:00

When ejabberd stops, send stream close to clients (thanks to Alexey Shchepin)(EJAB-1112)

SVN Revision: 2852
This commit is contained in:
Badlop 2010-01-03 00:35:51 +00:00
parent 15a27c0566
commit 7cbda8badb
2 changed files with 24 additions and 0 deletions

View File

@ -77,6 +77,8 @@ start(_, _) ->
prep_stop(State) ->
stop_modules(),
ejabberd_admin:stop(),
broadcast_c2s_shutdown(),
timer:sleep(5000),
State.
%% All the processes were killed when this function is called
@ -198,6 +200,13 @@ add_windows_nameservers() ->
lists:foreach(fun(IPT) -> inet_db:add_ns(IPT) end, IPTs).
broadcast_c2s_shutdown() ->
Children = supervisor:which_children(ejabberd_c2s_sup),
lists:foreach(
fun({_, C2SPid, _, _}) ->
C2SPid ! system_shutdown
end, Children).
%%%
%%% PID file
%%%

View File

@ -1304,6 +1304,21 @@ handle_info({route, From, To, Packet}, StateName, StateData) ->
handle_info({'DOWN', Monitor, _Type, _Object, _Info}, _StateName, StateData)
when Monitor == StateData#state.socket_monitor ->
{stop, normal, StateData};
handle_info(system_shutdown, StateName, StateData) ->
case StateName of
wait_for_stream ->
Header = io_lib:format(?STREAM_HEADER,
["none", ?MYNAME, " version='1.0'", ""]),
send_text(StateData, Header),
send_element(StateData, ?SERR_SYSTEM_SHUTDOWN),
send_text(StateData, ?STREAM_TRAILER),
ok;
_ ->
send_element(StateData, ?SERR_SYSTEM_SHUTDOWN),
send_text(StateData, ?STREAM_TRAILER),
ok
end,
{stop, normal, StateData};
handle_info(Info, StateName, StateData) ->
?ERROR_MSG("Unexpected info: ~p", [Info]),
fsm_next_state(StateName, StateData).