Software /
code /
prosody
Diff
net/server_epoll.lua @ 11264:2cdcf55c6dd5
Merge 0.11->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 08 Jan 2021 23:56:27 +0100 |
parent | 11239:06a5919e2496 |
parent | 11262:2c559953ad41 |
child | 11267:97077089f3c2 |
line wrap: on
line diff
--- a/net/server_epoll.lua Fri Jan 08 17:32:06 2021 +0100 +++ b/net/server_epoll.lua Fri Jan 08 23:56:27 2021 +0100 @@ -119,10 +119,10 @@ local elapsed = monotonic(); local now = realtime(); local peek = timers:peek(); + local readd; while peek do if peek > elapsed then - next_delay = peek - elapsed; break; end @@ -130,15 +130,31 @@ local ok, ret = xpcall(timer, traceback, now, id); if ok and type(ret) == "number" then local next_time = elapsed+ret; - timers:insert(timer, next_time); + -- Delay insertion of timers to be re-added + -- so they don't get called again this tick + if readd then + readd[id] = { timer, next_time }; + else + readd = { [id] = { timer, next_time } }; + end elseif not ok then log("error", "Error in timer: %s", ret); end peek = timers:peek(); end + + if readd then + for _, timer in pairs(readd) do + timers:insert(timer[1], timer[2]); + end + peek = timers:peek(); + end + if peek == nil then return next_delay; + else + next_delay = peek - elapsed; end if next_delay < min_wait then