From 5acb354989a2474feed3d83446c098cf6b4ea311 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 6 Jan 2023 02:31:21 +0100 Subject: 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 --- net/server_epoll.lua | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'net') diff --git a/net/server_epoll.lua b/net/server_epoll.lua index b269bd9c..66a60b5e 100644 --- a/net/server_epoll.lua +++ b/net/server_epoll.lua @@ -1082,8 +1082,33 @@ local function setquitting(quit) 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 @@ local function loop(once) 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 -- cgit v1.2.3