close(Ref) ->
xmpp_stream_in:close(Ref).
--spec close(pid(), boolean()) -> ok;
- (state(), boolean()) -> state().
-close(Ref, SendTrailer) ->
- xmpp_stream_in:close(Ref, SendTrailer).
+-spec close(pid(), atom()) -> ok;
+ (state(), atom()) -> state().
+close(Ref, Reason) ->
+ xmpp_stream_in:close(Ref, Reason).
-spec stop(pid()) -> ok;
(state()) -> no_return().
-export([handle_unexpected_info/2, handle_unexpected_cast/2,
reject_unauthenticated_packet/2, process_closed/2]).
%% API
--export([stop/1, close/1, send/2, update_state/2, establish/1,
+-export([stop/1, close/1, close/2, send/2, update_state/2, establish/1,
host_up/1, host_down/1]).
-include("ejabberd.hrl").
close(Ref) ->
xmpp_stream_in:close(Ref).
+close(Ref, Reason) ->
+ xmpp_stream_in:close(Ref, Reason).
+
stop(Ref) ->
xmpp_stream_in:stop(Ref).
-export([process_auth_result/2, process_closed/2, handle_unexpected_info/2,
handle_unexpected_cast/2, process_downgraded/2]).
%% API
--export([start/3, start_link/3, connect/1, close/1, stop/1, send/2,
+-export([start/3, start_link/3, connect/1, close/1, close/2, stop/1, send/2,
route/2, establish/1, update_state/2, host_up/1, host_down/1]).
-include("ejabberd.hrl").
close(Ref) ->
xmpp_stream_out:close(Ref).
+-spec close(pid(), atom()) -> ok;
+ (state(), atom()) -> state().
+close(Ref, Reason) ->
+ xmpp_stream_out:close(Ref, Reason).
+
-spec stop(pid()) -> ok;
(state()) -> no_return().
stop(Ref) ->
-protocol({xep, 114, '1.6'}).
%% ejabberd_socket callbacks
--export([start/2, start_link/2, socket_type/0]).
+-export([start/2, start_link/2, socket_type/0, close/1, close/2]).
%% ejabberd_config callbacks
-export([opt_type/1, transform_listen_option/2]).
%% xmpp_stream_in callbacks
send(Stream, Pkt) ->
xmpp_stream_in:send(Stream, Pkt).
+-spec close(pid()) -> ok;
+ (state()) -> state().
+close(Ref) ->
+ xmpp_stream_in:close(Ref).
+
+-spec close(pid(), atom()) -> ok;
+ (state(), atom()) -> state().
+close(Ref, Reason) ->
+ xmpp_stream_in:close(Ref, Reason).
+
%%%===================================================================
%%% xmpp_stream_in callbacks
%%%===================================================================
JID,
case ejabberd_sm:get_session_pid(User, Server, Resource)
of
- Pid when is_pid(Pid) -> ejabberd_c2s:close(Pid, _SendTrailer = false);
+ Pid when is_pid(Pid) -> ejabberd_c2s:close(Pid, ping_timeout);
_ -> ok
end;
_ -> ok
{timeout, TRef, ack_timeout}) ->
?DEBUG("Timed out waiting for stream management acknowledgement of ~s",
[jid:encode(JID)]),
- State1 = State#{stop_reason => {socket, timeout}},
- State2 = Mod:close(State1, _SendTrailer = false),
- {stop, transition_to_pending(State2)};
+ {stop, Mod:close(State, ack_timeout)};
c2s_handle_info(#{mgmt_state := pending, jid := JID, mod := Mod} = State,
{timeout, _, pending_timeout}) ->
?DEBUG("Timed out waiting for resumption of stream for ~s",
-type state() :: map().
-type stop_reason() :: {stream, reset | {in | out, stream_error()}} |
{tls, inet:posix() | atom() | binary()} |
- {socket, inet:posix() | closed | timeout} |
+ {socket, inet:posix() | atom()} |
internal_failure.
-export_type([state/0, stop_reason/0]).
-callback init(list()) -> {ok, state()} | {error, term()} | ignore.
-spec close(pid()) -> ok;
(state()) -> state().
close(Ref) ->
- close(Ref, true).
-
--spec close(pid(), boolean()) -> ok;
- (state(), boolean()) -> state().
-close(Pid, SendTrailer) when is_pid(Pid) ->
- cast(Pid, {close, SendTrailer});
-close(#{owner := Owner} = State, SendTrailer) when Owner == self() ->
- if SendTrailer -> send_trailer(State);
- true -> close_socket(State)
+ close(Ref, closed).
+
+-spec close(pid(), atom()) -> ok;
+ (state(), atom()) -> state().
+close(Pid, Reason) when is_pid(Pid) ->
+ cast(Pid, {close, Reason});
+close(#{owner := Owner} = State, Reason) when Owner == self() ->
+ case is_disconnected(State) of
+ true -> State;
+ false ->
+ _IgnoreState = close_socket(State),
+ process_stream_end({socket, Reason}, State)
end;
close(_, _) ->
erlang:error(badarg).
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({close, Reason}, State) ->
+ noreply(close(State, Reason));
handle_cast(Cast, #{mod := Mod} = State) ->
noreply(try Mod:handle_cast(Cast, State)
catch _:undef -> State
{tls, inet:posix() | atom() | binary()} |
{pkix, binary()} |
{auth, atom() | binary() | string()} |
- {socket, inet:posix() | closed | timeout} |
+ {socket, inet:posix() | atom()} |
internal_failure.
-export_type([state/0, stop_reason/0]).
-callback init(list()) -> {ok, state()} | {error, term()} | ignore.
-spec close(pid()) -> ok;
(state()) -> state().
close(Ref) ->
- close(Ref, true).
-
--spec close(pid(), boolean()) -> ok;
- (state(), boolean()) -> state().
-close(Pid, SendTrailer) when is_pid(Pid) ->
- cast(Pid, {close, SendTrailer});
-close(#{owner := Owner} = State, SendTrailer) when Owner == self() ->
- if SendTrailer -> send_trailer(State);
- true -> close_socket(State)
+ close(Ref, closed).
+
+-spec close(pid(), atom()) -> ok;
+ (state(), atom()) -> state().
+close(Pid, Reason) when is_pid(Pid) ->
+ cast(Pid, {close, Reason});
+close(#{owner := Owner} = State, Reason) when Owner == self() ->
+ case is_disconnected(State) of
+ true -> State;
+ false ->
+ _IgnoreState = close_socket(State),
+ process_stream_end({socket, Reason}, State)
end;
close(_, _) ->
erlang:error(badarg).
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({close, Reason}, State) ->
+ noreply(close(State, Reason));
handle_cast(Cast, #{mod := Mod} = State) ->
noreply(try Mod:handle_cast(Cast, State)
catch _:undef -> State