Software /
code /
prosody
Comparison
net/server_select.lua @ 11741:dcf38ac6a38c
net.server: Add a predrain callaback just before writes
Allows sneaking in things in the write buffer just before it's sent to
the network stack. For example ack requests, compression flushes or
other things that make sense to send after stanzas or other things.
This ensures any additional trailing data sent is included in the same
write, and possibly the same TCP packet. Other methods used such as
timers or nextTick might not have the same effect as it depends on
scheduling.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 16 Aug 2021 12:34:52 +0200 |
parent | 11068:988ddd57e851 |
child | 12480:7e9ebdc75ce4 |
comparison
equal
deleted
inserted
replaced
11740:b92f2abe0bda | 11741:dcf38ac6a38c |
---|---|
292 local pending | 292 local pending |
293 | 293 |
294 local dispatch = listeners.onincoming | 294 local dispatch = listeners.onincoming |
295 local status = listeners.onstatus | 295 local status = listeners.onstatus |
296 local disconnect = listeners.ondisconnect | 296 local disconnect = listeners.ondisconnect |
297 local predrain = listeners.onpredrain | |
297 local drain = listeners.ondrain | 298 local drain = listeners.ondrain |
298 local onreadtimeout = listeners.onreadtimeout; | 299 local onreadtimeout = listeners.onreadtimeout; |
299 local detach = listeners.ondetach | 300 local detach = listeners.ondetach |
300 | 301 |
301 local bufferqueue = { } -- buffer array | 302 local bufferqueue = { } -- buffer array |
336 detach(self) -- Notify listener that it is no longer responsible for this connection | 337 detach(self) -- Notify listener that it is no longer responsible for this connection |
337 end | 338 end |
338 dispatch = listeners.onincoming | 339 dispatch = listeners.onincoming |
339 disconnect = listeners.ondisconnect | 340 disconnect = listeners.ondisconnect |
340 status = listeners.onstatus | 341 status = listeners.onstatus |
342 predrain = listeners.onpredrain | |
341 drain = listeners.ondrain | 343 drain = listeners.ondrain |
342 handler.onreadtimeout = listeners.onreadtimeout | 344 handler.onreadtimeout = listeners.onreadtimeout |
343 detach = listeners.ondetach | 345 detach = listeners.ondetach |
344 if listeners.onattach then | 346 if listeners.onattach then |
345 listeners.onattach(self, data) | 347 listeners.onattach(self, data) |
549 if pending then | 551 if pending then |
550 pending = nil | 552 pending = nil |
551 if listeners.onconnect then | 553 if listeners.onconnect then |
552 listeners.onconnect(handler); | 554 listeners.onconnect(handler); |
553 end | 555 end |
556 end | |
557 if predrain then | |
558 predrain(handler); | |
554 end | 559 end |
555 buffer = table_concat( bufferqueue, "", 1, bufferqueuelen ) | 560 buffer = table_concat( bufferqueue, "", 1, bufferqueuelen ) |
556 succ, err, byte = send( socket, buffer, 1, bufferlen ) | 561 succ, err, byte = send( socket, buffer, 1, bufferlen ) |
557 count = ( succ or byte or 0 ) * STAT_UNIT | 562 count = ( succ or byte or 0 ) * STAT_UNIT |
558 sendtraffic = sendtraffic + count | 563 sendtraffic = sendtraffic + count |