Make sure that we send each time <close> before closing websocket connection

This commit is contained in:
Paweł Chmielowski 2015-03-25 17:08:43 +01:00
parent d9ad26b4ec
commit de26af3fdb
1 changed files with 13 additions and 1 deletions

View File

@ -187,7 +187,19 @@ handle_sync_event({send_xml, Packet}, _From, StateName,
skip ->
ok
end,
{reply, ok, StateName, StateData};
SN2 = case Packet2 of
{xmlstreamelement, #xmlel{name = <<"close">>}} ->
stream_end_sent;
_ ->
StateName
end,
{reply, ok, SN2, StateData};
handle_sync_event(close, _From, StateName, #state{ws = {_, WsPid}, rfc_compilant = true} = StateData)
when StateName /= stream_end_sent ->
Close = #xmlel{name = <<"close">>,
attrs = [{<<"xmlns">>, <<"urn:ietf:params:xml:ns:xmpp-framing">>}]},
WsPid ! {send, xml:element_to_binary(Close)},
{stop, normal, StateData};
handle_sync_event(close, _From, _StateName, StateData) ->
{stop, normal, StateData}.