Mercurial > prosody-hg
comparison 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 |
| parents | 29685403be32 |
| children | f33887f925e1 |
comparison
equal
deleted
inserted
replaced
| 12826:944c7f0f1a9e | 12827:0605d4f03e25 |
|---|---|
| 1080 else | 1080 else |
| 1081 quitting = nil; | 1081 quitting = nil; |
| 1082 end | 1082 end |
| 1083 end | 1083 end |
| 1084 | 1084 |
| 1085 local function loop_once() | |
| 1086 runtimers(); -- Ignore return value because we only do this once | |
| 1087 local fd, r, w = poll:wait(0); | |
| 1088 if fd then | |
| 1089 local conn = fds[fd]; | |
| 1090 if conn then | |
| 1091 if r then | |
| 1092 conn:onreadable(); | |
| 1093 end | |
| 1094 if w then | |
| 1095 conn:onwritable(); | |
| 1096 end | |
| 1097 else | |
| 1098 log("debug", "Removing unknown fd %d", fd); | |
| 1099 poll:del(fd); | |
| 1100 end | |
| 1101 else | |
| 1102 return fd, r; | |
| 1103 end | |
| 1104 end | |
| 1105 | |
| 1085 -- Main loop | 1106 -- Main loop |
| 1086 local function loop(once) | 1107 local function loop(once) |
| 1108 if once then | |
| 1109 return loop_once(); | |
| 1110 end | |
| 1111 | |
| 1087 repeat | 1112 repeat |
| 1088 local t = runtimers(cfg.max_wait, cfg.min_wait); | 1113 local t = runtimers(cfg.max_wait, cfg.min_wait); |
| 1089 local fd, r, w = poll:wait(t); | 1114 local fd, r, w = poll:wait(t); |
| 1090 while fd do | 1115 while fd do |
| 1091 local conn = fds[fd]; | 1116 local conn = fds[fd]; |
| 1103 fd, r, w = poll:wait(0); | 1128 fd, r, w = poll:wait(0); |
| 1104 end | 1129 end |
| 1105 if r ~= "timeout" and r ~= "signal" then | 1130 if r ~= "timeout" and r ~= "signal" then |
| 1106 log("debug", "epoll_wait error: %s[%d]", r, w); | 1131 log("debug", "epoll_wait error: %s[%d]", r, w); |
| 1107 end | 1132 end |
| 1108 until once or (quitting and next(fds) == nil); | 1133 until (quitting and next(fds) == nil); |
| 1109 return quitting; | 1134 return quitting; |
| 1110 end | 1135 end |
| 1111 | 1136 |
| 1112 return { | 1137 return { |
| 1113 get_backend = function () return "epoll"; end; | 1138 get_backend = function () return "epoll"; end; |
