aboutsummaryrefslogtreecommitdiffstats
path: root/net/server_select.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-08-16 12:34:52 +0200
committerKim Alvefur <zash@zash.se>2021-08-16 12:34:52 +0200
commitd06ae1629513e0a8ab8c1a24566226dddc93e8e1 (patch)
tree1734b65d5c33a62a267fdf8394066b89fa732570 /net/server_select.lua
parentb686dda4afa8f519830997dc88386a37e371d47e (diff)
downloadprosody-d06ae1629513e0a8ab8c1a24566226dddc93e8e1.tar.gz
prosody-d06ae1629513e0a8ab8c1a24566226dddc93e8e1.zip
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.
Diffstat (limited to 'net/server_select.lua')
-rw-r--r--net/server_select.lua5
1 files changed, 5 insertions, 0 deletions
diff --git a/net/server_select.lua b/net/server_select.lua
index 09c1c027..eea850ce 100644
--- a/net/server_select.lua
+++ b/net/server_select.lua
@@ -294,6 +294,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
local dispatch = listeners.onincoming
local status = listeners.onstatus
local disconnect = listeners.ondisconnect
+ local predrain = listeners.onpredrain
local drain = listeners.ondrain
local onreadtimeout = listeners.onreadtimeout;
local detach = listeners.ondetach
@@ -338,6 +339,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
dispatch = listeners.onincoming
disconnect = listeners.ondisconnect
status = listeners.onstatus
+ predrain = listeners.onpredrain
drain = listeners.ondrain
handler.onreadtimeout = listeners.onreadtimeout
detach = listeners.ondetach
@@ -552,6 +554,9 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
listeners.onconnect(handler);
end
end
+ if predrain then
+ predrain(handler);
+ end
buffer = table_concat( bufferqueue, "", 1, bufferqueuelen )
succ, err, byte = send( socket, buffer, 1, bufferlen )
count = ( succ or byte or 0 ) * STAT_UNIT