Просмотр исходного кода

Merge branch 'master' of github.com:emqtt/emqttd

Feng 10 лет назад
Родитель
Сommit
33b5d3b3ef
2 измененных файлов с 10 добавлено и 6 удалено
  1. 8 4
      src/emqttd_util.erl
  2. 2 2
      src/priority_queue.erl

+ 8 - 4
src/emqttd_util.erl

@@ -25,10 +25,8 @@
 %%%-----------------------------------------------------------------------------
 -module(emqttd_util).
 
--export([apply_module_attributes/1,
-         all_module_attributes/1,
-         cancel_timer/1,
-         now_to_secs/0, now_to_secs/1]).
+-export([apply_module_attributes/1, all_module_attributes/1, cancel_timer/1,
+         now_to_secs/0, now_to_secs/1, now_to_ms/0, now_to_ms/1]).
 
 -export([integer_to_binary/1]).
 
@@ -94,3 +92,9 @@ now_to_secs() ->
 now_to_secs({MegaSecs, Secs, _MicroSecs}) ->
     MegaSecs * 1000000 + Secs.
 
+now_to_ms() ->
+    now_to_ms(os:timestamp()).
+
+now_to_ms({MegaSecs, Secs, MicroSecs}) ->
+    (MegaSecs * 1000000 + Secs) * 1000 + round(MicroSecs/1000).
+

+ 2 - 2
src/priority_queue.erl

@@ -98,8 +98,8 @@ len({pqueue, Queues}) ->
 
 plen(0, {queue, _R, _F, L}) ->
     L;
-plen(P, {queue, _R, _F, _}) ->
-    erlang:error(badarg, [P]);
+plen(_, {queue, _R, _F, _}) ->
+    0;
 plen(P, {pqueue, Queues}) ->
     case lists:keysearch(maybe_negate_priority(P), 1, Queues) of
         {value, {_, Q}} -> len(Q);