Software /
code /
prosody
Diff
net/server_select.lua @ 3002:d1f864ed44c0
net.server_select, net.server_event: Support for ondrain listener callback for when send buffer is empty
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 05 May 2010 15:24:24 +0100 |
parent | 3001:fa00c6f563b4 |
child | 3003:48871a549b4c |
line wrap: on
line diff
--- a/net/server_select.lua Wed May 05 15:23:17 2010 +0100 +++ b/net/server_select.lua Wed May 05 15:24:24 2010 +0100 @@ -252,6 +252,7 @@ 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 @@ dispatch = listeners.onincoming disconnect = listeners.ondisconnect status = listeners.onstatus + drain = listeners.ondrain end handler.getstats = function( ) return readtraffic, sendtraffic @@ -437,7 +439,7 @@ 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 @@ _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