# HG changeset patch # User Kim Alvefur # Date 1517611560 -3600 # Node ID 174fd716c9fa85c093f12e5c4f3d922212c4ac58 # Parent c9bdb4dfed96bbbed4caf42fc9625372427c979e server_epoll: Rework how socket readyness is detected diff -r c9bdb4dfed96 -r 174fd716c9fa net/server_epoll.lua --- a/net/server_epoll.lua Fri Feb 02 19:48:04 2018 +0000 +++ b/net/server_epoll.lua Fri Feb 02 23:46:00 2018 +0100 @@ -505,9 +505,10 @@ if self.tls and not self._tls then return self:starttls(); else - self.onwriteable = interface.onconnect; + self.onwriteable = interface.onfirstwritable; + self.onreadable = interface.onfirstreadable; self:setwritetimeout(); - return self:setflags(false, true); + return self:setflags(true, true); end end @@ -537,15 +538,24 @@ -- Connected! function interface:onconnect() + self:setflags(true, false); + self:on("connect"); +end + +function interface:onfirstwritable() + self.onreadable = nil; self.onwriteable = nil; - self:setflags(true, false); - if not self._connected then - self._connected = true; - self:on("connect"); - end + self:onconnect(); return self:onwriteable(); end +function interface:onfirstreadable() + self.onreadable = nil; + self.onwriteable = nil; + self:onconnect(); + return self:onreadable(); +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