net.server_epoll: Ensure timeouts match epoll flags

Read and write timeouts should usually match whether we want to read or
write.
This commit is contained in:
Kim Alvefur 2021-07-17 14:54:48 +02:00
parent aba20a09bf
commit a30d4e1518

View file

@ -430,6 +430,7 @@ function interface:onreadable()
err = "timeout"; err = "timeout";
elseif err == "wantwrite" then elseif err == "wantwrite" then
self:set(nil, true); self:set(nil, true);
self:setwritetimeout();
err = "timeout"; err = "timeout";
elseif err == "timeout" and not self._connected then elseif err == "timeout" and not self._connected then
err = "connection timeout"; err = "connection timeout";
@ -510,8 +511,10 @@ function interface:onwritable()
end end
if err == "wantwrite" or err == "timeout" then if err == "wantwrite" or err == "timeout" then
self:set(nil, true); self:set(nil, true);
self:setwritetimeout();
elseif err == "wantread" then elseif err == "wantread" then
self:set(true, nil); self:set(true, nil);
self:setreadtimeout();
elseif err ~= "timeout" then elseif err ~= "timeout" then
self:on("disconnect", err); self:on("disconnect", err);
self:destroy(); self:destroy();
@ -553,6 +556,7 @@ interface.send = interface.write;
function interface:close() function interface:close()
if self.writebuffer and (self.writebuffer[1] or type(self.writebuffer) == "string") then if self.writebuffer and (self.writebuffer[1] or type(self.writebuffer) == "string") then
self:set(false, true); -- Flush final buffer contents self:set(false, true); -- Flush final buffer contents
self:setreadtimeout(false);
self:setwritetimeout(); self:setwritetimeout();
self.write, self.send = noop, noop; -- No more writing self.write, self.send = noop, noop; -- No more writing
self:debug("Close after writing remaining buffered data"); self:debug("Close after writing remaining buffered data");
@ -772,11 +776,13 @@ end
function interface:pause() function interface:pause()
self:noise("Pause reading"); self:noise("Pause reading");
self:setreadtimeout(false);
return self:set(false); return self:set(false);
end end
function interface:resume() function interface:resume()
self:noise("Resume reading"); self:noise("Resume reading");
self:setreadtimeout();
return self:set(true); return self:set(true);
end end