Match {error,einval}
This commit is contained in:
parent
80a7cbf09e
commit
6472457342
|
@ -252,8 +252,13 @@ handle_info({keepalive, start, Interval}, State = #client_state{connection = Con
|
||||||
{error, Error} -> {error, Error}
|
{error, Error} -> {error, Error}
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
KeepAlive = emqttd_keepalive:start(StatFun, Interval, {keepalive, check}),
|
case emqttd_keepalive:start(StatFun, Interval, {keepalive, check}) of
|
||||||
{noreply, State#client_state{keepalive = KeepAlive}, hibernate};
|
{ok, KeepAlive} ->
|
||||||
|
{noreply, State#client_state{keepalive = KeepAlive}, hibernate};
|
||||||
|
{error, Error} ->
|
||||||
|
?LOG(warning, "Keepalive error - ~p", [Error], State),
|
||||||
|
shutdown(Error, State)
|
||||||
|
end;
|
||||||
|
|
||||||
handle_info({keepalive, check}, State = #client_state{keepalive = KeepAlive}) ->
|
handle_info({keepalive, check}, State = #client_state{keepalive = KeepAlive}) ->
|
||||||
case emqttd_keepalive:check(KeepAlive) of
|
case emqttd_keepalive:check(KeepAlive) of
|
||||||
|
|
|
@ -29,14 +29,18 @@
|
||||||
-export_type([keepalive/0]).
|
-export_type([keepalive/0]).
|
||||||
|
|
||||||
%% @doc Start a keepalive
|
%% @doc Start a keepalive
|
||||||
-spec(start(fun(), integer(), any()) -> undefined | keepalive()).
|
-spec(start(fun(), integer(), any()) -> {ok, keepalive()} | {error, any()}).
|
||||||
start(_, 0, _) ->
|
start(_, 0, _) ->
|
||||||
undefined;
|
{ok, #keepalive{}};
|
||||||
start(StatFun, TimeoutSec, TimeoutMsg) ->
|
start(StatFun, TimeoutSec, TimeoutMsg) ->
|
||||||
{ok, StatVal} = StatFun(),
|
case StatFun() of
|
||||||
#keepalive{statfun = StatFun, statval = StatVal,
|
{ok, StatVal} ->
|
||||||
tsec = TimeoutSec, tmsg = TimeoutMsg,
|
{ok, #keepalive{statfun = StatFun, statval = StatVal,
|
||||||
tref = timer(TimeoutSec, TimeoutMsg)}.
|
tsec = TimeoutSec, tmsg = TimeoutMsg,
|
||||||
|
tref = timer(TimeoutSec, TimeoutMsg)}};
|
||||||
|
{error, Error} ->
|
||||||
|
{error, Error}
|
||||||
|
end.
|
||||||
|
|
||||||
%% @doc Check keepalive, called when timeout.
|
%% @doc Check keepalive, called when timeout.
|
||||||
-spec(check(keepalive()) -> {ok, keepalive()} | {error, any()}).
|
-spec(check(keepalive()) -> {ok, keepalive()} | {error, any()}).
|
||||||
|
@ -59,12 +63,11 @@ resume(KeepAlive = #keepalive{tsec = TimeoutSec, tmsg = TimeoutMsg}) ->
|
||||||
|
|
||||||
%% @doc Cancel Keepalive
|
%% @doc Cancel Keepalive
|
||||||
-spec(cancel(keepalive()) -> ok).
|
-spec(cancel(keepalive()) -> ok).
|
||||||
cancel(#keepalive{tref = TRef}) ->
|
cancel(#keepalive{tref = TRef}) when is_reference(TRef) ->
|
||||||
cancel(TRef);
|
erlang:cancel_timer(TRef),
|
||||||
cancel(undefined) ->
|
|
||||||
ok;
|
ok;
|
||||||
cancel(TRef) ->
|
cancel(_) ->
|
||||||
catch erlang:cancel_timer(TRef).
|
ok.
|
||||||
|
|
||||||
timer(Sec, Msg) ->
|
timer(Sec, Msg) ->
|
||||||
erlang:send_after(timer:seconds(Sec), self(), Msg).
|
erlang:send_after(timer:seconds(Sec), self(), Msg).
|
||||||
|
|
Loading…
Reference in New Issue