Changeset

11659:00295a8e5bcf

net.server_epoll: Separate handling of new incoming and outgoing connections The :init method is more suited for new outgoing connections, which is why it uses the connect_timeout setting. Depending on whether a newly accepted connection is to a Direct TLS port or not, it should be handled differently, and was already. The :starttls method sets up timeouts on its own, so the one set in :init was not needed. Newly accepted plain TCP connections don't need a write timeout set, a read timeout is enough.
author Kim Alvefur <zash@zash.se>
date Thu, 08 Jul 2021 17:52:59 +0200
parents 11658:36942fa001b4
children 11660:68f0196ece2a
files net/server_epoll.lua
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/net/server_epoll.lua	Sat Oct 31 00:33:29 2020 +0100
+++ b/net/server_epoll.lua	Thu Jul 08 17:52:59 2021 +0200
@@ -562,6 +562,8 @@
 		self.onwritable = interface.tlshandshake;
 		self.onreadable = interface.tlshandshake;
 		self:set(true, true);
+		self:setreadtimeout(cfg.ssl_handshake_timeout);
+		self:setwritetimeout(cfg.ssl_handshake_timeout);
 		self:debug("Prepared to start TLS");
 	end
 end
@@ -691,15 +693,17 @@
 	end
 	local client = wrapsocket(conn, self, nil, self.listeners);
 	client:debug("New connection %s on server %s", client, self);
-	client:init();
 	if self.tls_direct then
+		client:add(true, true);
 		client:starttls(self.tls_ctx);
 	else
+		client:add(true, false);
+		client:setreadtimeout();
 		client:onconnect();
 	end
 end
 
--- Initialization
+-- Initialization for outgoing connections
 function interface:init()
 	self:setwritetimeout(cfg.connect_timeout);
 	return self:add(true, true);