net.server_epoll: Factor Direct TLS handling out of connection initialization
authorKim Alvefur <zash@zash.se>
Thu, 13 Sep 2018 17:28:50 +0200
changeset 9309 35c128b42509
parent 9308 f14c81fd44a4
child 9310 feaef6215bb8
net.server_epoll: Factor Direct TLS handling out of connection initialization Eventually it should be possible to create a socket that has a TLS context but that does not automatically start TLS on connect.
net/server_epoll.lua
--- a/net/server_epoll.lua	Thu Sep 13 16:18:59 2018 +0100
+++ b/net/server_epoll.lua	Thu Sep 13 17:28:50 2018 +0200
@@ -454,6 +454,7 @@
 		self.onreadable = nil;
 		self._tls = true;
 		self:on("status", "ssl-handshake-complete");
+		self.init = nil; -- Restore default method
 		self:init();
 	elseif err == "wantread" then
 		log("debug", "TLS handshake on %s to wait until readable", self);
@@ -488,6 +489,9 @@
 	if client.getsockname then
 		conn.sockname, conn.sockport = client:getsockname();
 	end
+	if tls_ctx then
+		conn.init = interface.starttls;
+	end
 	return conn;
 end
 
@@ -507,12 +511,8 @@
 
 -- Initialization
 function interface:init()
-	if self.tls_ctx and not self._tls then
-		return self:starttls();
-	else
-		self:setwritetimeout();
-		return self:setflags(true, true);
-	end
+	self:setwritetimeout();
+	return self:setflags(true, true);
 end
 
 function interface:pause()