]> granicus.if.org Git - ejabberd/commitdiff
Let shaper cope with low resolution system clock
authorChristophe Romain <christophe.romain@process-one.net>
Fri, 29 Apr 2016 08:57:34 +0000 (10:57 +0200)
committerChristophe Romain <christophe.romain@process-one.net>
Fri, 29 Apr 2016 08:57:34 +0000 (10:57 +0200)
We no longer rely on getting unique values from clock source, so we need
to handle cope with systems which does not have a microsecond resolution
on system clock (such as MS Windows)

src/shaper.erl

index a136c2130d70dfb470588fe26b4101a8ce3e38ec..eb82b8faabed28d1942b415f07bf3a8ba2eaf47c 100644 (file)
@@ -124,9 +124,13 @@ update(#maxrate{} = State, Size) ->
               true -> 0
            end,
     NextNow = p1_time_compat:system_time(micro_seconds) + Pause * 1000,
+    Div = case NextNow - State#maxrate.lasttime of
+        0 -> 1;
+        V -> V
+    end,
     {State#maxrate{lastrate =
                       (State#maxrate.lastrate +
-                         1000000 * Size / (NextNow - State#maxrate.lasttime))
+                         1000000 * Size / Div)
                         / 2,
                   lasttime = NextNow},
      Pause}.