# HG changeset patch # User Matthew Wild # Date 1319669881 14400 # Node ID 424e14d3f99bd50627fcfe1226f8f73ee5ced6ef # Parent 5356664ef9d4d00d129c638baccb1dd6996a3058# Parent e7c501d203b0aef4c8d85893ef237ce66ee0131f Merge with Zash diff -r e7c501d203b0 -r 424e14d3f99b Makefile diff -r e7c501d203b0 -r 424e14d3f99b net/dns.lua --- a/net/dns.lua Tue Oct 18 01:22:44 2011 +0200 +++ b/net/dns.lua Wed Oct 26 18:58:01 2011 -0400 @@ -705,7 +705,7 @@ end end end - else self.cache = {}; end + else self.cache = setmetatable({}, cache_metatable); end end diff -r e7c501d203b0 -r 424e14d3f99b util/json.lua --- a/util/json.lua Tue Oct 18 01:22:44 2011 +0200 +++ b/util/json.lua Wed Oct 26 18:58:01 2011 -0400 @@ -168,7 +168,7 @@ skipwhitespace(); if ch == "/" and peek == "*" then skipstarcomment(); - elseif ch == "/" and peek == "*" then + elseif ch == "/" and peek == "/" then skiplinecomment(); else return; diff -r e7c501d203b0 -r 424e14d3f99b util/watchdog.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/util/watchdog.lua Wed Oct 26 18:58:01 2011 -0400 @@ -0,0 +1,34 @@ +local timer = require "util.timer"; +local setmetatable = setmetatable; +local os_time = os.time; + +module "watchdog" + +local watchdog_methods = {}; +local watchdog_mt = { __index = watchdog_methods }; + +function new(timeout, callback) + local watchdog = setmetatable({ timeout = timeout, last_reset = os_time(), callback = callback }, watchdog_mt); + timer.add_task(timeout+1, function (current_time) + local last_reset = watchdog.last_reset; + if not last_reset then + return; + end + local time_left = (last_reset + timeout) - current_time; + if time_left < 0 then + return watchdog.callback(); + end + return time_left + 1; + end); + return watchdog; +end + +function watchdog_methods:reset() + self.last_reset = os_time(); +end + +function watchdog_methods:cancel() + self.last_reset = nil; +end + +return _M;