From 408f9b515e6a400018297c6c85c907b039f868b7 Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Tue, 4 Apr 2017 09:52:42 +0300 Subject: [PATCH] Fix c2s connection close on demand Fixes #1652 --- src/mod_ping.erl | 2 +- src/xmpp_stream_in.erl | 10 ++++++++++ src/xmpp_stream_out.erl | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/mod_ping.erl b/src/mod_ping.erl index 2256b577c..1164bf44a 100644 --- a/src/mod_ping.erl +++ b/src/mod_ping.erl @@ -146,7 +146,7 @@ handle_cast({iq_pong, JID, timeout}, State) -> JID, case ejabberd_sm:get_session_pid(User, Server, Resource) of - Pid when is_pid(Pid) -> ejabberd_c2s:close(Pid); + Pid when is_pid(Pid) -> ejabberd_c2s:close(Pid, _SendTrailer = false); _ -> ok end; _ -> ok diff --git a/src/xmpp_stream_in.erl b/src/xmpp_stream_in.erl index b781bdf14..7d5a7e0b4 100644 --- a/src/xmpp_stream_in.erl +++ b/src/xmpp_stream_in.erl @@ -271,6 +271,16 @@ handle_cast({send, Pkt}, State) -> noreply(send_pkt(State, Pkt)); handle_cast(stop, State) -> {stop, normal, State}; +handle_cast({close, SendTrailer}, #{mod := Mod} = State) -> + noreply( + case is_disconnected(State) of + true -> State; + false -> + State1 = close(State, SendTrailer), + try Mod:handle_stream_end({socket, closed}, State1) + catch _:undef -> stop(State1) + end + end); handle_cast(Cast, #{mod := Mod} = State) -> noreply(try Mod:handle_cast(Cast, State) catch _:undef -> State diff --git a/src/xmpp_stream_out.erl b/src/xmpp_stream_out.erl index d0a39158d..7f6291a57 100644 --- a/src/xmpp_stream_out.erl +++ b/src/xmpp_stream_out.erl @@ -302,6 +302,16 @@ handle_cast({send, Pkt}, State) -> noreply(send_pkt(State, Pkt)); handle_cast(stop, State) -> {stop, normal, State}; +handle_cast({close, SendTrailer}, #{mod := Mod} = State) -> + noreply( + case is_disconnected(State) of + true -> State; + false -> + State1 = close(State, SendTrailer), + try Mod:handle_stream_end({socket, closed}, State1) + catch _:undef -> stop(State1) + end + end); handle_cast(Cast, #{mod := Mod} = State) -> noreply(try Mod:handle_cast(Cast, State) catch _:undef -> State