25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-26 17:38:45 +01:00

Make sure stream trailer is sent in the very end

This commit is contained in:
Evgeniy Khramtsov 2017-04-14 20:56:01 +03:00
parent 0a7eb33772
commit 5c23187d2c
2 changed files with 14 additions and 12 deletions

View File

@ -445,7 +445,8 @@ process_invalid_xml(#{lang := MyLang} = State, El, Reason) ->
process_stream_end(_, #{stream_state := disconnected} = State) ->
State;
process_stream_end(Reason, #{mod := Mod} = State) ->
State1 = send_trailer(State),
State1 = State#{stream_timeout => infinity,
stream_state => disconnected},
try Mod:handle_stream_end(Reason, State1)
catch _:undef -> stop(State1)
end.
@ -1081,21 +1082,21 @@ send_trailer(State) ->
socket_send(#{socket := Sock, sockmod := SockMod,
stream_state := StateName,
xmlns := NS,
stream_header_sent := true}, Pkt) when StateName /= disconnected ->
stream_header_sent := true}, Pkt) ->
case Pkt of
trailer ->
SockMod:send_trailer(Sock);
#stream_start{} ->
#stream_start{} when StateName /= disconnected ->
SockMod:send_header(Sock, xmpp:encode(Pkt));
_ when StateName /= disconnected ->
SockMod:send_element(Sock, xmpp:encode(Pkt, NS));
_ ->
SockMod:send_element(Sock, xmpp:encode(Pkt, NS))
{error, closed}
end;
socket_send(_, _) ->
{error, closed}.
-spec close_socket(state()) -> state().
close_socket(#{stream_state := disconnected} = State) ->
State;
close_socket(#{sockmod := SockMod, socket := Socket} = State) ->
SockMod:close(Socket),
State#{stream_timeout => infinity,

View File

@ -444,7 +444,8 @@ process_invalid_xml(#{lang := MyLang} = State, El, Reason) ->
process_stream_end(_, #{stream_state := disconnected} = State) ->
State;
process_stream_end(Reason, #{mod := Mod} = State) ->
State1 = send_trailer(State),
State1 = State#{stream_timeout => infinity,
stream_state => disconnected},
try Mod:handle_stream_end(Reason, State1)
catch _:undef -> stop(State1)
end.
@ -745,14 +746,16 @@ send_error(State, Pkt, Err) ->
-spec socket_send(state(), xmpp_element() | xmlel() | trailer) -> ok | {error, inet:posix()}.
socket_send(#{sockmod := SockMod, socket := Socket, xmlns := NS,
stream_state := StateName}, Pkt) when StateName /= disconnected ->
stream_state := StateName}, Pkt) ->
case Pkt of
trailer ->
SockMod:send_trailer(Socket);
#stream_start{} ->
#stream_start{} when StateName /= disconnected ->
SockMod:send_header(Socket, xmpp:encode(Pkt));
_ when StateName /= disconnected ->
SockMod:send_element(Socket, xmpp:encode(Pkt, NS));
_ ->
SockMod:send_element(Socket, xmpp:encode(Pkt, NS))
{error, closed}
end;
socket_send(_, _) ->
{error, closed}.
@ -763,8 +766,6 @@ send_trailer(State) ->
close_socket(State).
-spec close_socket(state()) -> state().
close_socket(#{stream_state := disconnected} = State) ->
State;
close_socket(State) ->
case State of
#{sockmod := SockMod, socket := Socket} ->