aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-07-08 22:01:19 +0200
committerKim Alvefur <zash@zash.se>2020-07-08 22:01:19 +0200
commitf2ae89296c1f2c4a2b20d259d40ab3fe14b4a87d (patch)
tree67026bf23b5207901595fecd0abfe5d1fc695ecf
parent14cdec45c594346fe87eb9a5f76e08f3924aba48 (diff)
downloadprosody-f2ae89296c1f2c4a2b20d259d40ab3fe14b4a87d.tar.gz
prosody-f2ae89296c1f2c4a2b20d259d40ab3fe14b4a87d.zip
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.
-rw-r--r--net/cqueues.lua14
1 files changed, 14 insertions, 0 deletions
diff --git a/net/cqueues.lua b/net/cqueues.lua
index 84d59f15..65d2a019 100644
--- a/net/cqueues.lua
+++ b/net/cqueues.lua
@@ -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 @@ if server.cq then -- server provides cqueues object
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"