implemented timeout_action: none | kill. default is none

SVN Revision: 2402
This commit is contained in:
Evgeniy Khramtsov 2009-07-30 10:25:54 +00:00
parent 458b28eeff
commit 548be039b3
2 changed files with 19 additions and 0 deletions

View File

@ -32,6 +32,7 @@
%% External exports
-export([start/2,
stop/1,
start_link/2,
send_text/2,
send_element/2,
@ -151,6 +152,9 @@ socket_type() ->
get_presence(FsmRef) ->
gen_fsm:sync_send_all_state_event(FsmRef, {get_presence}, 1000).
stop(FsmRef) ->
gen_fsm:send_event(FsmRef, closed).
%%%----------------------------------------------------------------------
%%% Callback functions from gen_fsm
%%%----------------------------------------------------------------------

View File

@ -58,6 +58,7 @@
-record(state, {host = "",
send_pings = ?DEFAULT_SEND_PINGS,
ping_interval = ?DEFAULT_PING_INTERVAL,
timeout_action = none,
timers = ?DICT:new()}).
%%====================================================================
@ -95,6 +96,7 @@ stop(Host) ->
init([Host, Opts]) ->
SendPings = gen_mod:get_opt(send_pings, Opts, ?DEFAULT_SEND_PINGS),
PingInterval = gen_mod:get_opt(ping_interval, Opts, ?DEFAULT_PING_INTERVAL),
TimeoutAction = gen_mod:get_opt(timeout_action, Opts, none),
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
mod_disco:register_feature(Host, ?NS_PING),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_PING,
@ -115,6 +117,7 @@ init([Host, Opts]) ->
{ok, #state{host = Host,
send_pings = SendPings,
ping_interval = PingInterval,
timeout_action = TimeoutAction,
timers = ?DICT:new()}}.
terminate(_Reason, #state{host = Host}) ->
@ -142,6 +145,18 @@ handle_cast({stop_ping, JID}, State) ->
handle_cast({iq_pong, JID, timeout}, State) ->
Timers = del_timer(JID, State#state.timers),
ejabberd_hooks:run(user_ping_timeout, State#state.host, [JID]),
case State#state.timeout_action of
kill ->
#jid{user = User, server = Server, resource = Resource} = JID,
case ejabberd_sm:get_session_pid(User, Server, Resource) of
Pid when is_pid(Pid) ->
ejabberd_c2s:stop(Pid);
_ ->
ok
end;
_ ->
ok
end,
{noreply, State#state{timers = Timers}};
handle_cast(_Msg, State) ->
{noreply, State}.