Changeset

9499:36e379f058c8

net.server: Swich method for connecting sockets with remotes LuaSocket TCP sockets have have both :connect and :setpeername, which are the exact same function, however UDP sockets only have :setpeername. Switching to :setpeername allows most of this code to be generic wrt TCP/UDP.
author Kim Alvefur <zash@zash.se>
date Fri, 12 Oct 2018 17:36:34 +0200
parents 9498:cc593002f2e2
children 9500:7de89d66cbb9
files net/server_epoll.lua net/server_event.lua net/server_select.lua
diffstat 3 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/net/server_epoll.lua	Fri Oct 12 17:28:08 2018 +0200
+++ b/net/server_epoll.lua	Fri Oct 12 17:36:34 2018 +0200
@@ -645,7 +645,7 @@
 	local conn, err = create();
 	local ok, err = conn:settimeout(0);
 	if not ok then return ok, err; end
-	local ok, err = conn:connect(addr, port);
+	local ok, err = conn:setpeername(addr, port);
 	if not ok and err ~= "timeout" then return ok, err; end
 	local client = wrapsocket(conn, nil, read_size, listeners, tls_ctx)
 	local ok, err = client:init();
--- a/net/server_event.lua	Fri Oct 12 17:28:08 2018 +0200
+++ b/net/server_event.lua	Fri Oct 12 17:36:34 2018 +0200
@@ -747,7 +747,7 @@
 		return nil, err
 	end
 	client:settimeout( 0 )  -- set nonblocking
-	local res, err = client:connect( addr, serverport )  -- connect
+	local res, err = client:setpeername( addr, serverport )  -- connect
 	if res or ( err == "timeout" ) then
 		local ip, port = client:getsockname( )
 		local interface = wrapclient( client, ip, serverport, listener, pattern, sslctx )
--- a/net/server_select.lua	Fri Oct 12 17:28:08 2018 +0200
+++ b/net/server_select.lua	Fri Oct 12 17:36:34 2018 +0200
@@ -1032,7 +1032,7 @@
 		return nil, err
 	end
 	client:settimeout( 0 )
-	local ok, err = client:connect( address, port )
+	local ok, err = client:setpeername( address, port )
 	if ok or err == "timeout" or err == "Operation already in progress" then
 		return wrapclient( client, address, port, listeners, pattern, sslctx )
 	else