aboutsummaryrefslogtreecommitdiffstats
path: root/net/server_select.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-10-25 15:12:59 +0200
committerKim Alvefur <zash@zash.se>2018-10-25 15:12:59 +0200
commit031dc2e2a0450b25e16bbc534b29522e0ee52793 (patch)
treef10f829a3a201917528af2117ebe78b410d1fab8 /net/server_select.lua
parente1846ef9a35e2e91a3c844ef489be780811aa1b0 (diff)
downloadprosody-031dc2e2a0450b25e16bbc534b29522e0ee52793.tar.gz
prosody-031dc2e2a0450b25e16bbc534b29522e0ee52793.zip
net.server: Add an API for holding writes of outgoing data
Diffstat (limited to 'net/server_select.lua')
-rw-r--r--net/server_select.lua31
1 files changed, 19 insertions, 12 deletions
diff --git a/net/server_select.lua b/net/server_select.lua
index 745e1f49..693cee5e 100644
--- a/net/server_select.lua
+++ b/net/server_select.lua
@@ -485,20 +485,27 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
out_error( "server.lua, lock() is deprecated" )
handler.lock_read (self, switch)
if switch == true then
- local tmp = _sendlistlen
- _sendlistlen = removesocket( _sendlist, socket, _sendlistlen )
- _writetimes[ handler ] = nil
- if _sendlistlen ~= tmp then
- nosend = true
- end
+ handler.pause_writes (self)
elseif switch == false then
- if nosend then
- nosend = false
- write( "" )
- end
+ handler.resume_writes (self)
end
return noread, nosend
end
+ handler.pause_writes = function (self)
+ local tmp = _sendlistlen
+ _sendlistlen = removesocket( _sendlist, socket, _sendlistlen )
+ _writetimes[ handler ] = nil
+ if _sendlistlen ~= tmp then
+ nosend = true
+ end
+ end
+ handler.resume_writes = function (self)
+ if nosend then
+ nosend = false
+ write( "" )
+ end
+ end
+
local _readbuffer = function( ) -- this function reads data
local buffer, err, part = receive( socket, pattern ) -- receive buffer with "pattern"
if not err or (err == "wantread" or err == "timeout") then -- received something
@@ -716,7 +723,7 @@ local function link(sender, receiver, buffersize)
function receiver.sendbuffer()
_sendbuffer();
if sender_locked and receiver.bufferlen() < buffersize then
- sender:resume(); -- Unlock now
+ sender:lock_read(false); -- Unlock now
sender_locked = nil;
end
end
@@ -726,7 +733,7 @@ local function link(sender, receiver, buffersize)
_readbuffer();
if not sender_locked and receiver.bufferlen() >= buffersize then
sender_locked = true;
- sender:pause();
+ sender:lock_read(true);
end
end
sender:set_mode("*a");