Diff

net/server_epoll.lua @ 9835:20bf5b47c1fb

net.server: New API for creating server listeners server.listen(interface, port, listeners, options);
author Kim Alvefur <zash@zash.se>
date Thu, 13 Sep 2018 21:16:37 +0200
parent 9825:5ccce16c6449
child 9847:adc0672b700e
line wrap: on
line diff
--- a/net/server_epoll.lua	Wed Feb 27 10:29:10 2019 +0100
+++ b/net/server_epoll.lua	Thu Sep 13 21:16:37 2018 +0200
@@ -637,7 +637,7 @@
 	self:on("connect");
 end
 
-local function addserver(addr, port, listeners, read_size, tls_ctx)
+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);
@@ -645,10 +645,10 @@
 		conn = conn;
 		created = gettime();
 		listeners = listeners;
-		read_size = read_size;
+		read_size = config and config.read_size;
 		onreadable = interface.onacceptable;
-		tls_ctx = tls_ctx;
-		tls_direct = tls_ctx and true or false;
+		tls_ctx = config and config.tls_ctx;
+		tls_direct = config and config.tls_direct;
 		sockname = addr;
 		sockport = port;
 	}, interface_mt);
@@ -657,6 +657,15 @@
 end
 
 -- COMPAT
+local function addserver(addr, port, listeners, read_size, tls_ctx)
+	return listen(addr, port, listeners, {
+		read_size = read_size;
+		tls_ctx = tls_ctx;
+		tls_direct = tls_ctx and true or false;
+	});
+end
+
+-- COMPAT
 local function wrapclient(conn, addr, port, listeners, read_size, tls_ctx)
 	local client = wrapsocket(conn, nil, read_size, listeners, tls_ctx);
 	if not client.peername then
@@ -792,6 +801,7 @@
 	addserver = addserver;
 	addclient = addclient;
 	add_task = addtimer;
+	listen = listen;
 	at = at;
 	loop = loop;
 	closeall = closeall;