2023-08-11 13:20:17 (UTC-03:00)
Marcel Rodrigues <marcelgmr@gmail.com>
tcp: report epoll_wait() errors but don't crash
diff --git a/lib/ludweb/tcp.lua b/lib/ludweb/tcp.lua index c55ed99..6617216 100644 --- a/lib/ludweb/tcp.lua +++ b/lib/ludweb/tcp.lua @@ -121,7 +121,14 @@ function TCP:run() local running = true while running do nfds = C.epoll_wait(efd, evs, curfds, -1) - assert(nfds >= 0, "epoll_wait error") + if nfds < 0 then + local errno = ffi.errno() + local ts = os.date("%F %T") + local errs = {[4]="EINTR", [9]="EBADF", [14]="EFAULT", [22]="EINVAL"} + local msg = "[%s] epoll_wait() failed with %s\n" + io.stderr:write(msg:format(ts, errs[errno])) + end + -- the loop below will run zero times if nfds < 1, ignoring errors for n = 0, nfds-1 do if evs[n].data.fd == self.sockfd then local newfd = C.accept(self.sockfd, client_addr, addr_size)