# HG changeset patch # User Kim Alvefur # Date 1594238479 -7200 # Node ID 37b884d675f7bb87432f0f4f274ff4f96e2d5658 # Parent f3fc0f799dc43dc62e73dfd70abeadfa05c34158 net.cqueues: Fix resuming after timeouts net.cqueues previously relied on timers instead of fd events sometimes. Under net.server_select, it would have called cq:loop() on every iteration of the main loop, which was probably not optimal. diff -r f3fc0f799dc4 -r 37b884d675f7 net/cqueues.lua --- a/net/cqueues.lua Wed Jul 08 21:39:10 2020 +0200 +++ b/net/cqueues.lua Wed Jul 08 22:01:19 2020 +0200 @@ -9,6 +9,7 @@ local server = require "net.server"; local cqueues = require "cqueues"; +local timer = require "util.timer"; assert(cqueues.VERSION >= 20150113, "cqueues newer than 20150113 required") -- Create a single top level cqueue @@ -18,8 +19,21 @@ cq = server.cq; elseif server.watchfd then cq = cqueues.new(); + local timeout = timer.add_task(cq:timeout() or 0, function () + -- FIXME It should be enough to reschedule this timeout instead of replacing it, but this does not work. See https://issues.prosody.im/1572 + assert(cq:loop(0)); + return cq:timeout(); + end); server.watchfd(cq:pollfd(), function () assert(cq:loop(0)); + local t = cq:timeout(); + if t then + timer.stop(timeout); + timeout = timer.add_task(cq:timeout(), function () + assert(cq:loop(0)); + return cq:timeout(); + end); + end end); else error "NYI"