aboutsummaryrefslogtreecommitdiffstats
path: root/net/server_select.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2010-05-05 15:24:24 +0100
committerMatthew Wild <mwild1@gmail.com>2010-05-05 15:24:24 +0100
commit3c7eb58b08e7f416d73f86061706674d37f83c4f (patch)
treefbd2c8cecb1944a0c773220c1eb52ab40fa35046 /net/server_select.lua
parent242d67b43e37e5fa4a831011f70a2429957f7b6b (diff)
downloadprosody-3c7eb58b08e7f416d73f86061706674d37f83c4f.tar.gz
prosody-3c7eb58b08e7f416d73f86061706674d37f83c4f.zip
net.server_select, net.server_event: Support for ondrain listener callback for when send buffer is empty
Diffstat (limited to 'net/server_select.lua')
-rw-r--r--net/server_select.lua7
1 files changed, 6 insertions, 1 deletions
diff --git a/net/server_select.lua b/net/server_select.lua
index 475e8aca..9bc112bb 100644
--- a/net/server_select.lua
+++ b/net/server_select.lua
@@ -252,6 +252,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
local dispatch = listeners.onincoming
local status = listeners.onstatus
local disconnect = listeners.ondisconnect
+ local drain = listeners.ondrain
local bufferqueue = { } -- buffer array
local bufferqueuelen = 0 -- end of buffer array
@@ -284,6 +285,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
dispatch = listeners.onincoming
disconnect = listeners.ondisconnect
status = listeners.onstatus
+ drain = listeners.ondrain
end
handler.getstats = function( )
return readtraffic, sendtraffic
@@ -437,7 +439,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
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") or (part and string_len(part) > 0) then -- received something
+ if not err or (err == "wantread" or err == "timeout") then -- received something
local buffer = buffer or part or ""
local len = string_len( buffer )
if len > maxreadlen then
@@ -479,6 +481,9 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
_sendlistlen = removesocket( _sendlist, socket, _sendlistlen ) -- delete socket from writelist
_ = needtls and handler:starttls(nil, true)
_writetimes[ handler ] = nil
+ if drain then
+ drain(handler)
+ end
_ = toclose and handler:close( )
return true
elseif byte and ( err == "timeout" or err == "wantwrite" ) then -- want write