Diff

net/server_epoll.lua @ 12827:0605d4f03e25

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
author Kim Alvefur <zash@zash.se>
date Fri, 06 Jan 2023 02:31:21 +0100
parent 12594:29685403be32
child 12828:f33887f925e1
line wrap: on
line diff
--- 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