chore(stomp): fix dialyzer warnings

This commit is contained in:
JianBo He 2021-11-02 14:30:00 +08:00
parent cc6ea6e4dd
commit 2c4d3d1d24
3 changed files with 29 additions and 17 deletions

View File

@ -26,8 +26,7 @@
-logger_header("[Stomp-Conn]"). -logger_header("[Stomp-Conn]").
-import(emqx_misc, -import(emqx_misc,
[ maybe_apply/2 [ start_timer/2
, start_timer/2
]). ]).
-export([ start_link/3 -export([ start_link/3
@ -92,6 +91,13 @@
-define(ENABLED(X), (X =/= undefined)). -define(ENABLED(X), (X =/= undefined)).
-dialyzer({nowarn_function, [ ensure_stats_timer/2
]}).
-dialyzer({no_return, [ init/1
, init_state/3
]}).
start_link(Transport, Sock, ProtoEnv) -> start_link(Transport, Sock, ProtoEnv) ->
{ok, proc_lib:spawn_link(?MODULE, init, [[Transport, Sock, ProtoEnv]])}. {ok, proc_lib:spawn_link(?MODULE, init, [[Transport, Sock, ProtoEnv]])}.
@ -115,13 +121,7 @@ info(sockname, #state{sockname = Sockname}) ->
info(sockstate, #state{sockstate = SockSt}) -> info(sockstate, #state{sockstate = SockSt}) ->
SockSt; SockSt;
info(active_n, #state{active_n = ActiveN}) -> info(active_n, #state{active_n = ActiveN}) ->
ActiveN; ActiveN.
info(stats_timer, #state{stats_timer = StatsTimer}) ->
StatsTimer;
info(limit_timer, #state{limit_timer = LimitTimer}) ->
LimitTimer;
info(limiter, #state{limiter = Limiter}) ->
maybe_apply(fun emqx_limiter:info/1, Limiter).
-spec stats(pid()|state()) -> emqx_types:stats(). -spec stats(pid()|state()) -> emqx_types:stats().
stats(CPid) when is_pid(CPid) -> stats(CPid) when is_pid(CPid) ->
@ -216,6 +216,12 @@ send(Data, Transport, Sock, ConnPid) ->
heartbeat(Transport, Sock) -> heartbeat(Transport, Sock) ->
Transport:send(Sock, <<$\n>>). Transport:send(Sock, <<$\n>>).
handle_call(info, _From, State) ->
{reply, info(State), State};
handle_call(stats, _From, State) ->
{reply, stats(State), State};
handle_call(discard, _From, State) -> handle_call(discard, _From, State) ->
%% TODO: send the DISCONNECT packet? %% TODO: send the DISCONNECT packet?
shutdown_and_reply(discared, ok, State); shutdown_and_reply(discared, ok, State);

View File

@ -20,6 +20,7 @@
-include("emqx_stomp.hrl"). -include("emqx_stomp.hrl").
-include_lib("emqx/include/emqx.hrl"). -include_lib("emqx/include/emqx.hrl").
-include_lib("emqx/include/types.hrl").
-include_lib("emqx/include/logger.hrl"). -include_lib("emqx/include/logger.hrl").
-include_lib("emqx/include/emqx_mqtt.hrl"). -include_lib("emqx/include/emqx_mqtt.hrl").
@ -55,7 +56,7 @@
%% Stomp ClientInfo %% Stomp ClientInfo
clientinfo :: emqx_types:clientinfo(), clientinfo :: emqx_types:clientinfo(),
%% Stomp Heartbeats %% Stomp Heartbeats
heart_beats :: emqx_stomp_hearbeat:heartbeat(), heart_beats :: maybe(emqx_stomp_hearbeat:heartbeat()),
%% Stomp Connection State %% Stomp Connection State
connected = false, connected = false,
%% Timers %% Timers
@ -65,13 +66,13 @@
%% Subscriptions %% Subscriptions
subscriptions = #{}, subscriptions = #{},
%% Send function %% Send function
sendfun :: function(), sendfun :: {function(), list()},
%% Heartbeat function %% Heartbeat function
heartfun :: function(), heartfun :: {function(), list()},
%% The confs for the connection %% The confs for the connection
%% TODO: put these configs into a public mem? %% TODO: put these configs into a public mem?
allow_anonymous, allow_anonymous :: maybe(boolean()),
default_user default_user :: maybe(list())
}). }).
-define(TIMER_TABLE, #{ -define(TIMER_TABLE, #{
@ -96,6 +97,10 @@
awaiting_rel_max awaiting_rel_max
]). ]).
-dialyzer({nowarn_function, [ check_acl/3
, init/2
]}).
-type(pstate() :: #pstate{}). -type(pstate() :: #pstate{}).
%% @doc Init protocol %% @doc Init protocol
@ -417,7 +422,7 @@ send(Msg = #message{topic = Topic, headers = Headers, payload = Payload},
{error, dropped, State} {error, dropped, State}
end; end;
send(Frame, State = #pstate{sendfun = {Fun, Args}}) -> send(Frame, State = #pstate{sendfun = {Fun, Args}}) when is_record(Frame, stomp_frame) ->
?LOG(info, "SEND Frame: ~s", [emqx_stomp_frame:format(Frame)]), ?LOG(info, "SEND Frame: ~s", [emqx_stomp_frame:format(Frame)]),
Data = emqx_stomp_frame:serialize(Frame), Data = emqx_stomp_frame:serialize(Frame),
?LOG(debug, "SEND ~p", [Data]), ?LOG(debug, "SEND ~p", [Data]),
@ -681,7 +686,7 @@ allow_anonymous(#pstate{allow_anonymous = AllowAnonymous}) ->
AllowAnonymous. AllowAnonymous.
ensure_connected(State = #pstate{conninfo = ConnInfo, ensure_connected(State = #pstate{conninfo = ConnInfo,
clientinfo = ClientInfo}) -> clientinfo = ClientInfo}) ->
NConnInfo = ConnInfo#{ NConnInfo = ConnInfo#{
connected => true, connected => true,
connected_at => erlang:system_time(millisecond) connected_at => erlang:system_time(millisecond)

View File

@ -94,7 +94,8 @@
-type(ver() :: ?MQTT_PROTO_V3 -type(ver() :: ?MQTT_PROTO_V3
| ?MQTT_PROTO_V4 | ?MQTT_PROTO_V4
| ?MQTT_PROTO_V5 | ?MQTT_PROTO_V5
| non_neg_integer()). | non_neg_integer()
| binary()).
-type(qos() :: ?QOS_0 | ?QOS_1 | ?QOS_2). -type(qos() :: ?QOS_0 | ?QOS_1 | ?QOS_2).
-type(qos_name() :: qos0 | at_most_once | -type(qos_name() :: qos0 | at_most_once |