25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

now using p1_fsm behaviour in c2s FSM (EJAB-1173)

SVN Revision: 2936
This commit is contained in:
Evgeniy Khramtsov 2010-01-28 13:00:04 +00:00
parent ce18cfb41b
commit 352afa7902
2 changed files with 3395 additions and 2185 deletions

5367
src/configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -28,7 +28,9 @@
-author('alexey@process-one.net'). -author('alexey@process-one.net').
-update_info({update, 0}). -update_info({update, 0}).
-behaviour(gen_fsm). -define(GEN_FSM, p1_fsm).
-behaviour(?GEN_FSM).
%% External exports %% External exports
-export([start/2, -export([start/2,
@ -104,8 +106,8 @@
%% Module start with or without supervisor: %% Module start with or without supervisor:
-ifdef(NO_TRANSIENT_SUPERVISORS). -ifdef(NO_TRANSIENT_SUPERVISORS).
-define(SUPERVISOR_START, gen_fsm:start(ejabberd_c2s, [SockData, Opts], -define(SUPERVISOR_START, ?GEN_FSM:start(ejabberd_c2s, [SockData, Opts],
?FSMOPTS)). fsm_limit_opts() ++ ?FSMOPTS)).
-else. -else.
-define(SUPERVISOR_START, supervisor:start_child(ejabberd_c2s_sup, -define(SUPERVISOR_START, supervisor:start_child(ejabberd_c2s_sup,
[SockData, Opts])). [SockData, Opts])).
@ -140,17 +142,18 @@ start(SockData, Opts) ->
?SUPERVISOR_START. ?SUPERVISOR_START.
start_link(SockData, Opts) -> start_link(SockData, Opts) ->
gen_fsm:start_link(ejabberd_c2s, [SockData, Opts], ?FSMOPTS). ?GEN_FSM:start_link(ejabberd_c2s, [SockData, Opts],
fsm_limit_opts() ++ ?FSMOPTS).
socket_type() -> socket_type() ->
xml_stream. xml_stream.
%% Return Username, Resource and presence information %% Return Username, Resource and presence information
get_presence(FsmRef) -> get_presence(FsmRef) ->
gen_fsm:sync_send_all_state_event(FsmRef, {get_presence}, 1000). ?GEN_FSM:sync_send_all_state_event(FsmRef, {get_presence}, 1000).
stop(FsmRef) -> stop(FsmRef) ->
gen_fsm:send_event(FsmRef, closed). ?GEN_FSM:send_event(FsmRef, closed).
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% Callback functions from gen_fsm %%% Callback functions from gen_fsm
@ -221,7 +224,7 @@ init([{SockMod, Socket}, Opts]) ->
%% Return list of all available resources of contacts, %% Return list of all available resources of contacts,
get_subscribed(FsmRef) -> get_subscribed(FsmRef) ->
gen_fsm:sync_send_all_state_event(FsmRef, get_subscribed, 1000). ?GEN_FSM:sync_send_all_state_event(FsmRef, get_subscribed, 1000).
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
%% Func: StateName/2 %% Func: StateName/2
@ -903,7 +906,7 @@ session_established({xmlstreamelement, El}, StateData) ->
session_established(timeout, StateData) -> session_established(timeout, StateData) ->
%% TODO: Options must be stored in state: %% TODO: Options must be stored in state:
Options = [], Options = [],
proc_lib:hibernate(gen_fsm, enter_loop, proc_lib:hibernate(?GEN_FSM, enter_loop,
[?MODULE, Options, session_established, StateData]), [?MODULE, Options, session_established, StateData]),
fsm_next_state(session_established, StateData); fsm_next_state(session_established, StateData);
@ -2153,6 +2156,14 @@ check_from(El, FromJID) ->
end end
end. end.
fsm_limit_opts() ->
case ejabberd_config:get_local_option(max_fsm_queue) of
N when is_integer(N) ->
[{max_queue, N}];
_ ->
[]
end.
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% JID Set memory footprint reduction code %%% JID Set memory footprint reduction code
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------