From 852e44959d04b56cbf3c761b1ab5e0547ae05cc7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 8 Jul 2021 17:52:59 +0200 Subject: 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. --- net/server_epoll.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'net') diff --git a/net/server_epoll.lua b/net/server_epoll.lua index 6618c204..d4a08d3d 100644 --- a/net/server_epoll.lua +++ b/net/server_epoll.lua @@ -562,6 +562,8 @@ function interface:starttls(tls_ctx) 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 @@ function interface:onacceptable() 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); -- cgit v1.2.3