diff options
author | Waqas Hussain <waqas20@gmail.com> | 2013-04-16 18:15:10 -0400 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2013-04-16 18:15:10 -0400 |
commit | 27f39498ff5718ad92a12e2a4677fee61446f7ab (patch) | |
tree | 2363b7bab68fc54000a42ede19d91b88bd966689 /net | |
parent | cc4fd7b37da281c49a3213e9de02df0f329619b2 (diff) | |
download | prosody-27f39498ff5718ad92a12e2a4677fee61446f7ab.tar.gz prosody-27f39498ff5718ad92a12e2a4677fee61446f7ab.zip |
net.server_select: Move socket timeout cleanup code out of a timer, into the select loop (which makes util.timer the only timer using server_select._addtimer).
Diffstat (limited to 'net')
-rw-r--r-- | net/server_select.lua | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/net/server_select.lua b/net/server_select.lua index 6592de9b..86c9daef 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -846,6 +846,26 @@ loop = function(once) -- this is the main loop of the program _closelist[ handler ] = nil; end _currenttime = luasocket_gettime( ) + + local difftime = os_difftime( _currenttime - _starttime ) + if difftime > _checkinterval then + _starttime = _currenttime + for handler, timestamp in pairs( _writetimes ) do + if os_difftime( _currenttime - timestamp ) > _sendtimeout then + --_writetimes[ handler ] = nil + handler.disconnect( )( handler, "send timeout" ) + handler:force_close() -- forced disconnect + end + end + for handler, timestamp in pairs( _readtimes ) do + if os_difftime( _currenttime - timestamp ) > _readtimeout then + --_readtimes[ handler ] = nil + handler.disconnect( )( handler, "read timeout" ) + handler:close( ) -- forced disconnect? + end + end + end + if _currenttime - _timer >= math_min(next_timer_time, 1) then next_timer_time = math_huge; for i = 1, _timerlistlen do @@ -921,28 +941,6 @@ use "setmetatable" ( _writetimes, { __mode = "k" } ) _timer = luasocket_gettime( ) _starttime = luasocket_gettime( ) -addtimer( function( ) - local difftime = os_difftime( _currenttime - _starttime ) - if difftime > _checkinterval then - _starttime = _currenttime - for handler, timestamp in pairs( _writetimes ) do - if os_difftime( _currenttime - timestamp ) > _sendtimeout then - --_writetimes[ handler ] = nil - handler.disconnect( )( handler, "send timeout" ) - handler:force_close() -- forced disconnect - end - end - for handler, timestamp in pairs( _readtimes ) do - if os_difftime( _currenttime - timestamp ) > _readtimeout then - --_readtimes[ handler ] = nil - handler.disconnect( )( handler, "read timeout" ) - handler:close( ) -- forced disconnect? - end - end - end - end -) - local function setlogger(new_logger) local old_logger = log; if new_logger then |