aboutsummaryrefslogtreecommitdiff
path: root/net.lua
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2010-01-06 03:10:18 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2010-01-06 03:10:18 +0100
commit8fe4cf436afd24877ebe0fb6d706cbafdc2cc4e7 (patch)
tree8669e66a82d3cf4c1a8c717a6834585b4529b576 /net.lua
parentd2a00d70579f6f71b638c39c8b3e11385e0376a3 (diff)
downloadvicious-legacy-8fe4cf436afd24877ebe0fb6d706cbafdc2cc4e7.tar.xz
net: sanitize time computation to avoid division by zero
Diffstat (limited to 'net.lua')
-rw-r--r--net.lua14
1 files changed, 7 insertions, 7 deletions
diff --git a/net.lua b/net.lua
index 1a98b6f..1fec49d 100644
--- a/net.lua
+++ b/net.lua
@@ -57,19 +57,19 @@ local function worker(format)
-- Default values on the first run
nets[name] = {}
uformat(args, name .. " down", 0)
- uformat(args, name .. " up", 0)
+ uformat(args, name .. " up", 0)
nets[name].time = os.time()
- else
- -- Net stats are absolute, substract our last reading
- local interval = os.time() - nets[name].time
+ else -- Net stats are absolute, substract our last reading
+ local interval = os.time() - nets[name].time > 0 and
+ os.time() - nets[name].time or 1
nets[name].time = os.time()
- local down = (recv - nets[name][1])/interval
- local up = (send - nets[name][2])/interval
+ local down = (recv - nets[name][1]) / interval
+ local up = (send - nets[name][2]) / interval
uformat(args, name .. " down", down)
- uformat(args, name .. " up", up)
+ uformat(args, name .. " up", up)
end
-- Store totals