Software /
code /
prosody
Changeset
4406:424e14d3f99b
Merge with Zash
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 26 Oct 2011 18:58:01 -0400 |
parents | 4404:5356664ef9d4 (diff) 4405:e7c501d203b0 (current diff) |
children | 4407:f78c6f5fa090 4410:2928a74357c8 |
files | Makefile |
diffstat | 3 files changed, 36 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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;
--- /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;