net: sanitize time computation to avoid division by zero

This commit is contained in:
Adrian C. (anrxc) 2010-01-06 03:10:18 +01:00
parent d2a00d7057
commit 8fe4cf436a
1 changed files with 7 additions and 7 deletions

14
net.lua
View File

@ -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