25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-26 16:26:24 +01:00

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

SVN Revision: 2859
This commit is contained in:
Badlop 2010-01-04 20:32:44 +00:00
parent 38dfef923c
commit 8c0cc95a55
2 changed files with 22 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
@ -186,6 +188,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

@ -1258,6 +1258,19 @@ 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 ->
send_header(StateData#state.streamid, ?MYNAME, "1.0", ""),
send_element(StateData, exmpp_stream:error('system-shutdown')),
send_text(StateData, ?STREAM_TRAILER),
ok;
_ ->
send_element(StateData, exmpp_stream:error('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).