net.server_epoll: Factor out single main loop step into its own function
This isn't actually used in Prosody, so no value in complicating the
real main loop because of it
--- a/net/server_epoll.lua Thu Dec 29 18:36:38 2022 +0100
+++ b/net/server_epoll.lua Fri Jan 06 02:31:21 2023 +0100
@@ -1082,8 +1082,33 @@
end
end
+local function loop_once()
+ runtimers(); -- Ignore return value because we only do this once
+ local fd, r, w = poll:wait(0);
+ if fd then
+ local conn = fds[fd];
+ if conn then
+ if r then
+ conn:onreadable();
+ end
+ if w then
+ conn:onwritable();
+ end
+ else
+ log("debug", "Removing unknown fd %d", fd);
+ poll:del(fd);
+ end
+ else
+ return fd, r;
+ end
+end
+
-- Main loop
local function loop(once)
+ if once then
+ return loop_once();
+ end
+
repeat
local t = runtimers(cfg.max_wait, cfg.min_wait);
local fd, r, w = poll:wait(t);
@@ -1105,7 +1130,7 @@
if r ~= "timeout" and r ~= "signal" then
log("debug", "epoll_wait error: %s[%d]", r, w);
end
- until once or (quitting and next(fds) == nil);
+ until (quitting and next(fds) == nil);
return quitting;
end