Changeset

5485:5147eed0a42e

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).
author Waqas Hussain <waqas20@gmail.com>
date Tue, 16 Apr 2013 18:15:10 -0400
parents 5484:17ce73907c48
children 5486:bcf27dbef6c6
files net/server_select.lua
diffstat 1 files changed, 20 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/net/server_select.lua	Wed Apr 17 21:30:44 2013 +0200
+++ b/net/server_select.lua	Tue Apr 16 18:15:10 2013 -0400
@@ -846,6 +846,26 @@
 			_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 @@
 _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