Software /
code /
prosody
Comparison
net/server_epoll.lua @ 12011:9dc36fdbdba1
net.server_epoll: Ensure calls to :write() return something
With opportunistic writes enabled, writes can return what :onwritable()
returns, thus :onwritable() should return something sensible at each
spot.
Should prevent whatever caused
> Error writing to connection: (nil)
Tho this was probably harmless
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 06 Dec 2021 10:59:14 +0100 |
parent | 11972:520ce76440ad |
child | 12091:7a48ccb084dd |
comparison
equal
deleted
inserted
replaced
12010:f995d62044fa | 12011:9dc36fdbdba1 |
---|---|
487 | 487 |
488 -- Called when socket is writable | 488 -- Called when socket is writable |
489 function interface:onwritable() | 489 function interface:onwritable() |
490 self._writing = true; -- prevent reentrant writes etc | 490 self._writing = true; -- prevent reentrant writes etc |
491 self:onconnect(); | 491 self:onconnect(); |
492 if not self.conn then return; end -- could have been closed in onconnect | 492 if not self.conn then return nil, "no-conn"; end -- could have been closed in onconnect |
493 self:on("predrain"); | 493 self:on("predrain"); |
494 local buffer = self.writebuffer; | 494 local buffer = self.writebuffer; |
495 local data = buffer or ""; | 495 local data = buffer or ""; |
496 if type(buffer) == "table" then | 496 if type(buffer) == "table" then |
497 if buffer[3] then | 497 if buffer[3] then |
540 elseif err ~= "timeout" then | 540 elseif err ~= "timeout" then |
541 self:on("disconnect", err); | 541 self:on("disconnect", err); |
542 self:destroy(); | 542 self:destroy(); |
543 return ok, err; | 543 return ok, err; |
544 end | 544 end |
545 return true, err; | |
545 end | 546 end |
546 | 547 |
547 -- The write buffer has been successfully emptied | 548 -- The write buffer has been successfully emptied |
548 function interface:ondrain() | 549 function interface:ondrain() |
549 return self:on("drain"); | 550 return self:on("drain"); |