diff options
author | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2017-04-30 19:01:47 +0300 |
---|---|---|
committer | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2017-04-30 19:01:47 +0300 |
commit | fddd6110e00df12c99a20a2cc9d074f5f4f1f965 (patch) | |
tree | 366575b855f1b2013db7eeb02ecb213f81c98c1f /src/mod_ping.erl | |
parent | 2b63d07329b2af63d63b14d237e63565f78e8018 (diff) |
Don't validate an option in gen_mod:get*opt() functions
The changes are very similar to those from previous commit:
* Now there is no need to pass validating function in
gen_mod:get_opt() and gen_mod:get_module_opt() functions,
because the modules' configuration keeps already validated values.
* New functions gen_mod:get_opt/2 and gen_mod:get_module_opt/3 are
introduced.
* Functions gen_mod:get_opt/4 and get_module_opt/5 are deprecated.
If the functions are still called, the "function" argument is
simply ignored.
* Validating callback Mod:listen_opt_type/1 is introduced to validate
listening options at startup.
Diffstat (limited to 'src/mod_ping.erl')
-rw-r--r-- | src/mod_ping.erl | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/src/mod_ping.erl b/src/mod_ping.erl index a16d9b2c4..038b1bc2d 100644 --- a/src/mod_ping.erl +++ b/src/mod_ping.erl @@ -95,8 +95,7 @@ reload(Host, NewOpts, OldOpts) -> init([Host, Opts]) -> process_flag(trap_exit, true), State = init_state(Host, Opts), - IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1, - no_queue), + IQDisc = gen_mod:get_opt(iqdisc, Opts, no_queue), register_iq_handlers(Host, IQDisc), case State#state.send_pings of true -> register_hooks(Host); @@ -115,9 +114,7 @@ handle_call(_Req, _From, State) -> handle_cast({reload, Host, NewOpts, OldOpts}, #state{timers = Timers} = OldState) -> - case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts, - fun gen_iq_handler:check_type/1, - one_queue) of + case gen_mod:is_equal_opt(iqdisc, NewOpts, OldOpts, one_queue) of {false, IQDisc, _} -> register_iq_handlers(Host, IQDisc); true -> ok end, @@ -200,19 +197,10 @@ user_send({Packet, #{jid := JID} = C2SState}) -> %% Internal functions %%==================================================================== init_state(Host, Opts) -> - SendPings = gen_mod:get_opt(send_pings, Opts, - fun(B) when is_boolean(B) -> B end, - ?DEFAULT_SEND_PINGS), - PingInterval = gen_mod:get_opt(ping_interval, Opts, - fun(I) when is_integer(I), I>0 -> I end, - ?DEFAULT_PING_INTERVAL), - PingAckTimeout = gen_mod:get_opt(ping_ack_timeout, Opts, - fun(I) when is_integer(I), I>0 -> I * 1000 end, - undefined), - TimeoutAction = gen_mod:get_opt(timeout_action, Opts, - fun(none) -> none; - (kill) -> kill - end, none), + SendPings = gen_mod:get_opt(send_pings, Opts, ?DEFAULT_SEND_PINGS), + PingInterval = gen_mod:get_opt(ping_interval, Opts, ?DEFAULT_PING_INTERVAL), + PingAckTimeout = gen_mod:get_opt(ping_ack_timeout, Opts), + TimeoutAction = gen_mod:get_opt(timeout_action, Opts, none), #state{host = Host, send_pings = SendPings, ping_interval = PingInterval, @@ -284,7 +272,7 @@ mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1; mod_opt_type(ping_interval) -> fun (I) when is_integer(I), I > 0 -> I end; mod_opt_type(ping_ack_timeout) -> - fun (I) when is_integer(I), I > 0 -> I end; + fun(I) when is_integer(I), I>0 -> timer:seconds(I) end; mod_opt_type(send_pings) -> fun (B) when is_boolean(B) -> B end; mod_opt_type(timeout_action) -> |