# HG changeset patch # User Kim Alvefur # Date 1519476376 -3600 # Node ID ba9fd886b34d7bff6181f648482010c4497173b9 # Parent 41b5f070d7bb8b3348daccc4907f365d4102cf12 net.server_epoll: Call onconnect listener on first successful read or write diff -r 41b5f070d7bb -r ba9fd886b34d net/server_epoll.lua --- a/net/server_epoll.lua Sat Feb 24 11:51:43 2018 +0100 +++ b/net/server_epoll.lua Sat Feb 24 13:46:16 2018 +0100 @@ -306,9 +306,11 @@ function interface:onreadable() local data, err, partial = self.conn:receive(self._pattern); if data then + self:onconnect(); self:on("incoming", data); else - if partial then + if partial and partial ~= "" then + self:onconnect(); self:on("incoming", partial, err); end if err == "wantread" then @@ -336,15 +338,17 @@ local data = t_concat(buffer); local ok, err, partial = self.conn:send(data); if ok then - for i = #buffer, 1, -1 do - buffer[i] = nil; + if data ~= "" then + for i = #buffer, 1, -1 do + buffer[i] = nil; + end + self:setflags(nil, false); + self:setwritetimeout(false); + self:ondrain(); -- Be aware of writes in ondrain end - self:setflags(nil, false); - self:setwritetimeout(false); - self:ondrain(); -- Be aware of writes in ondrain + self:onconnect(); return; - end - if partial then + elseif partial then buffer[1] = data:sub(partial+1); for i = #buffer, 2, -1 do buffer[i] = nil; @@ -505,8 +509,6 @@ if self.tls and not self._tls then return self:starttls(); else - self.onwriteable = interface.onfirstwritable; - self.onreadable = interface.onfirstreadable; self:setwritetimeout(); return self:setflags(true, true); end @@ -538,25 +540,8 @@ -- Connected! function interface:onconnect() - self:setflags(true, false); - if not self._connected then - self._connected = true; - self:on("connect"); - end -end - -function interface:onfirstwritable() - self.onreadable = nil; - self.onwriteable = nil; - self:onconnect(); - return self:onwriteable(); -end - -function interface:onfirstreadable() - self.onreadable = nil; - self.onwriteable = nil; - self:onconnect(); - return self:onreadable(); + self.onconnect = noop; + self:on("connect"); end local function addserver(addr, port, listeners, pattern, tls)