Changeset

7553:4f3e4a092348

net.server_epoll: Make addclient use wrapclient
author Kim Alvefur <zash@zash.se>
date Wed, 10 Aug 2016 20:57:05 +0200
parents 7552:f1ae74ebeb81
children 7554:c2decf88e249
files net/server_epoll.lua
diffstat 1 files changed, 14 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/net/server_epoll.lua	Wed Aug 10 20:55:31 2016 +0200
+++ b/net/server_epoll.lua	Wed Aug 10 20:57:05 2016 +0200
@@ -424,12 +424,6 @@
 	self.listeners.onconnect(self);
 end
 
-local function addclient(addr, port, listeners, pattern, tls)
-	local conn, err = socket.connect(addr, port);
-	if not conn then return conn, err; end
-	return wrapsocket(conn, nil, pattern, listeners, tls);
-end
-
 local function addserver(addr, port, listeners, pattern, tls)
 	local conn, err = socket.bind(addr, port, cfg.tcp_backlog);
 	if not conn then return conn, err; end
@@ -466,6 +460,20 @@
 	return client;
 end
 
+local function addclient(addr, port, listeners, pattern, tls)
+	local conn, err = socket.connect(addr, port);
+	if not conn then return conn, err; end
+	conn:settimeout(0);
+	local client = wrapclient(conn, addr, port, listeners, pattern, tls);
+	if tls then
+		client._tls = false;
+		client:starttls();
+	else
+		client:setflags(true, true);
+	end
+	return client;
+end
+
 local function link(from, to)
 	from.listeners = setmetatable({
 		onincoming = function (_, data)