# HG changeset patch # User Kim Alvefur # Date 1720369697 -7200 # Node ID da9be0ad4bbc136ce59be0fa243c04175b5251f5 # Parent dbf6e5404c7f9492467665b37f75df0c4fd6e16a net.server_event: Add 'wrapserver' API This enables accepting admin stream socket (UNIX) connections trough the same procedures as any other (TCP) socket, which avoids problems caused by using the wrapclient API, which ends up discarding early data due to only expecting early connection failure. Fixes #1867 diff -r dbf6e5404c7f -r da9be0ad4bbc net/server_event.lua --- a/net/server_event.lua Wed Jun 12 23:00:24 2024 +0200 +++ b/net/server_event.lua Sun Jul 07 18:28:17 2024 +0200 @@ -705,7 +705,10 @@ debug( "maximal connections reached, refuse client connection; accept delay:", delay ) return EV_TIMEOUT, delay -- delay for next accept attempt end - local client_ip, client_port = client:getpeername( ) + local client_ip, client_port = addr, port; + if client.getpeername then -- Only IP sockets have this method, UNIX sockets don't + client_ip, client_port = client:getpeername( ) + end interface._connections = interface._connections + 1 -- increase connection count local clientinterface = handleclient( client, client_ip, client_port, interface, pattern, listener, sslctx ) --vdebug( "client id:", clientinterface, "startssl:", startssl ) @@ -728,6 +731,17 @@ return interface end +local function wrapserver(conn, addr, port, listeners, config) + config = config or {} + if config.sslctx and not has_luasec then + debug "fatal error: luasec not found" + return nil, "luasec not found" + end + local interface = handleserver( conn, addr, port, config.read_size, listeners, config.tls_ctx, config.tls_direct) -- new server handler + debug( "new server created with id:", tostring(interface)) + return interface +end + local function listen(addr, port, listener, config) config = config or {} if config.sslctx and not has_luasec then @@ -917,6 +931,7 @@ listen = listen, addclient = addclient, wrapclient = wrapclient, + wrapserver = wrapserver, setquitting = setquitting, closeall = closeallservers, get_backend = get_backend,