-include("logger.hrl").
-include("xmpp.hrl").
--define(PUSH_BEFORE_TIMEOUT_SECS, 120).
+-define(PUSH_BEFORE_TIMEOUT_PERIOD, 120000). % 2 minutes.
-type c2s_state() :: ejabberd_c2s:state().
-spec mod_opt_type(atom()) -> econf:validator().
mod_opt_type(resume_timeout) ->
- econf:non_neg_int();
+ econf:either(
+ econf:int(0, 0),
+ econf:timeout(second));
mod_opt_type(wake_on_start) ->
econf:bool();
mod_opt_type(wake_on_timeout) ->
econf:bool().
mod_options(_Host) ->
- [{resume_timeout, 259200},
+ [{resume_timeout, timer:seconds(259200)},
{wake_on_start, false},
{wake_on_timeout, true}].
-spec maybe_start_wakeup_timer(c2s_state()) -> c2s_state().
maybe_start_wakeup_timer(#{push_wake_on_timeout := true,
push_resume_timeout := ResumeTimeout} = State)
- when is_integer(ResumeTimeout), ResumeTimeout > ?PUSH_BEFORE_TIMEOUT_SECS ->
- WakeTimeout = ResumeTimeout - ?PUSH_BEFORE_TIMEOUT_SECS,
+ when is_integer(ResumeTimeout), ResumeTimeout > ?PUSH_BEFORE_TIMEOUT_PERIOD ->
+ WakeTimeout = ResumeTimeout - ?PUSH_BEFORE_TIMEOUT_PERIOD,
?DEBUG("Scheduling wake-up timer to fire in ~B seconds", [WakeTimeout]),
- erlang:start_timer(timer:seconds(WakeTimeout), self(), push_keepalive),
+ erlang:start_timer(WakeTimeout, self(), push_keepalive),
State;
maybe_start_wakeup_timer(State) ->
State.
lserver := LServer, mgmt_timeout := Timeout} = State) ->
State1 = cancel_ack_timer(State),
?INFO_MSG("Waiting for resumption of stream for ~s", [jid:encode(JID)]),
- TRef = erlang:start_timer(timer:seconds(Timeout), self(), pending_timeout),
+ TRef = erlang:start_timer(Timeout, self(), pending_timeout),
State2 = State1#{mgmt_state => pending, mgmt_pending_timer => TRef},
ejabberd_hooks:run_fold(c2s_session_pending, LServer, State2, []);
transition_to_pending(State) ->
-spec restart_pending_timer(state(), non_neg_integer()) -> state().
restart_pending_timer(#{mgmt_pending_timer := TRef} = State, NewTimeout) ->
misc:cancel_timer(TRef),
- NewTRef = erlang:start_timer(timer:seconds(NewTimeout), self(),
- pending_timeout),
+ NewTRef = erlang:start_timer(NewTimeout, self(), pending_timeout),
State#{mgmt_pending_timer => NewTRef};
restart_pending_timer(State, _NewTimeout) ->
State.
mod_opt_type(max_ack_queue) ->
econf:pos_int(infinity);
mod_opt_type(resume_timeout) ->
- econf:non_neg_int();
+ econf:either(
+ econf:int(0, 0),
+ econf:timeout(second));
mod_opt_type(max_resume_timeout) ->
- econf:non_neg_int();
+ econf:either(
+ econf:int(0, 0),
+ econf:timeout(second));
mod_opt_type(ack_timeout) ->
econf:timeout(second, infinity);
mod_opt_type(resend_on_timeout) ->