25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +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) -> process_stream_end(_, #{stream_state := disconnected} = State) ->
State; State;
process_stream_end(Reason, #{mod := Mod} = 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) try Mod:handle_stream_end(Reason, State1)
catch _:undef -> stop(State1) catch _:undef -> stop(State1)
end. end.
@ -1081,21 +1082,21 @@ send_trailer(State) ->
socket_send(#{socket := Sock, sockmod := SockMod, socket_send(#{socket := Sock, sockmod := SockMod,
stream_state := StateName, stream_state := StateName,
xmlns := NS, xmlns := NS,
stream_header_sent := true}, Pkt) when StateName /= disconnected -> stream_header_sent := true}, Pkt) ->
case Pkt of case Pkt of
trailer -> trailer ->
SockMod:send_trailer(Sock); SockMod:send_trailer(Sock);
#stream_start{} -> #stream_start{} when StateName /= disconnected ->
SockMod:send_header(Sock, xmpp:encode(Pkt)); 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; end;
socket_send(_, _) -> socket_send(_, _) ->
{error, closed}. {error, closed}.
-spec close_socket(state()) -> state(). -spec close_socket(state()) -> state().
close_socket(#{stream_state := disconnected} = State) ->
State;
close_socket(#{sockmod := SockMod, socket := Socket} = State) -> close_socket(#{sockmod := SockMod, socket := Socket} = State) ->
SockMod:close(Socket), SockMod:close(Socket),
State#{stream_timeout => infinity, 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) -> process_stream_end(_, #{stream_state := disconnected} = State) ->
State; State;
process_stream_end(Reason, #{mod := Mod} = 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) try Mod:handle_stream_end(Reason, State1)
catch _:undef -> stop(State1) catch _:undef -> stop(State1)
end. end.
@ -745,14 +746,16 @@ send_error(State, Pkt, Err) ->
-spec socket_send(state(), xmpp_element() | xmlel() | trailer) -> ok | {error, inet:posix()}. -spec socket_send(state(), xmpp_element() | xmlel() | trailer) -> ok | {error, inet:posix()}.
socket_send(#{sockmod := SockMod, socket := Socket, xmlns := NS, socket_send(#{sockmod := SockMod, socket := Socket, xmlns := NS,
stream_state := StateName}, Pkt) when StateName /= disconnected -> stream_state := StateName}, Pkt) ->
case Pkt of case Pkt of
trailer -> trailer ->
SockMod:send_trailer(Socket); SockMod:send_trailer(Socket);
#stream_start{} -> #stream_start{} when StateName /= disconnected ->
SockMod:send_header(Socket, xmpp:encode(Pkt)); 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; end;
socket_send(_, _) -> socket_send(_, _) ->
{error, closed}. {error, closed}.
@ -763,8 +766,6 @@ send_trailer(State) ->
close_socket(State). close_socket(State).
-spec close_socket(state()) -> state(). -spec close_socket(state()) -> state().
close_socket(#{stream_state := disconnected} = State) ->
State;
close_socket(State) -> close_socket(State) ->
case State of case State of
#{sockmod := SockMod, socket := Socket} -> #{sockmod := SockMod, socket := Socket} ->