Feng 10 vuotta sitten
vanhempi
commit
4a175bfc68
4 muutettua tiedostoa jossa 15 lisäystä ja 12 poistoa
  1. 7 4
      src/emqttd_ctl.erl
  2. 6 6
      src/emqttd_metrics.erl
  3. 1 1
      src/emqttd_pubsub.erl
  4. 1 1
      src/emqttd_session.erl

+ 7 - 4
src/emqttd_ctl.erl

@@ -58,17 +58,20 @@ start_link() ->
 %% @doc Register a command
 %% @end
 %%------------------------------------------------------------------------------
--spec register_cmd(atom(), {module(), atom()}, list()) -> true.
+-spec register_cmd(atom(), {module(), atom()}, list()) -> ok.
 register_cmd(Cmd, MF, Opts) ->
-    gen_server:cast(?SERVER, {register_cmd, Cmd, MF, Opts}).
+    cast({register_cmd, Cmd, MF, Opts}).
 
 %%------------------------------------------------------------------------------
 %% @doc Unregister a command
 %% @end
 %%------------------------------------------------------------------------------
--spec unregister_cmd(atom()) -> true.
+-spec unregister_cmd(atom()) -> ok.
 unregister_cmd(Cmd) ->
-    gen_server:cast(?SERVER, {unregister_cmd, Cmd}).
+    cast({unregister_cmd, Cmd}).
+
+cast(Msg) ->
+    gen_server:cast(?SERVER, Msg).
 
 %%------------------------------------------------------------------------------
 %% @doc Run a command

+ 6 - 6
src/emqttd_metrics.erl

@@ -226,12 +226,12 @@ inc(Metric) ->
 %% @doc Increase metric value
 %% @end
 %%------------------------------------------------------------------------------
--spec inc(counter | gauge, atom()) -> non_neg_integer().
-inc(gauge, Metric) ->
-    inc(gauge, Metric, 1);
-inc(counter, Metric) ->
-    inc(counter, Metric, 1);
-inc(Metric, Val) when is_atom(Metric) and is_integer(Val) ->
+-spec inc({counter | gauge, atom()} | atom(), pos_integer()) -> non_neg_integer().
+inc({gauge, Metric}, Val) ->
+    inc(gauge, Metric, Val);
+inc({counter, Metric}, Val) ->
+    inc(counter, Metric, Val);
+inc(Metric, Val) when is_atom(Metric) ->
     inc(counter, Metric, Val).
 
 %%------------------------------------------------------------------------------

+ 1 - 1
src/emqttd_pubsub.erl

@@ -142,7 +142,7 @@ name(Id) ->
 %% @doc Create Topic or Subscription.
 %% @end
 %%------------------------------------------------------------------------------
--spec create(topic | subscription, binary()) -> ok | {error, any()}.
+-spec create(topic | subscription, binary() | {binary(), binary(), mqtt_qos()}) -> ok | {error, any()}.
 create(topic, Topic) when is_binary(Topic) ->
     Record = #mqtt_topic{topic = Topic, node = node()},
     case mnesia:transaction(fun add_topic/1, [Record]) of

+ 1 - 1
src/emqttd_session.erl

@@ -191,7 +191,7 @@ subscribe(SessPid, PacketId, TopicTable) ->
 %% @doc Publish message
 %% @end
 %%------------------------------------------------------------------------------
--spec publish(pid(), mqtt_message()) -> ok.
+-spec publish(pid(), mqtt_message()) -> ok | {error, any()}.
 publish(_SessPid, Msg = #mqtt_message{qos = ?QOS_0}) ->
     %% publish qos0 directly
     emqttd_pubsub:publish(Msg);