net.server_epoll: Add way to start accepting clients on an arbitrary server socket

This adds an escape hatch where things like UNIX sockets can be added.
This commit is contained in:
Kim Alvefur 2020-06-01 17:19:08 +02:00
parent f554caa3ac
commit 9708aab9b3

View file

@ -719,10 +719,7 @@ function interface:onconnect()
self:on("connect"); self:on("connect");
end end
local function listen(addr, port, listeners, config) local function wrapserver(conn, addr, port, listeners, config)
local conn, err = socket.bind(addr, port, cfg.tcp_backlog);
if not conn then return conn, err; end
conn:settimeout(0);
local server = setmetatable({ local server = setmetatable({
conn = conn; conn = conn;
created = realtime(); created = realtime();
@ -741,6 +738,13 @@ local function listen(addr, port, listeners, config)
return server; return server;
end end
local function listen(addr, port, listeners, config)
local conn, err = socket.bind(addr, port, cfg.tcp_backlog);
if not conn then return conn, err; end
conn:settimeout(0);
return wrapserver(conn, addr, port, listeners, config);
end
-- COMPAT -- COMPAT
local function addserver(addr, port, listeners, read_size, tls_ctx) local function addserver(addr, port, listeners, read_size, tls_ctx)
return listen(addr, port, listeners, { return listen(addr, port, listeners, {
@ -897,6 +901,7 @@ return {
closeall = closeall; closeall = closeall;
setquitting = setquitting; setquitting = setquitting;
wrapclient = wrapclient; wrapclient = wrapclient;
wrapserver = wrapserver;
watchfd = watchfd; watchfd = watchfd;
link = link; link = link;
set_config = function (newconfig) set_config = function (newconfig)