Comparison

net/server_select.lua @ 6541:a702786f4f31

net.server_select: Remove do-nothing os_difftime calls
author daurnimator <quae@daurnimator.com>
date Mon, 19 Jan 2015 14:01:11 -0500
parent 6540:31a8b3bfb31d
child 6542:32c84e1f706d
comparison
equal deleted inserted replaced
6540:31a8b3bfb31d 6541:a702786f4f31
36 local string = use "string" 36 local string = use "string"
37 local coroutine = use "coroutine" 37 local coroutine = use "coroutine"
38 38
39 --// lua lib methods //-- 39 --// lua lib methods //--
40 40
41 local os_difftime = os.difftime
42 local math_min = math.min 41 local math_min = math.min
43 local math_huge = math.huge 42 local math_huge = math.huge
44 local table_concat = table.concat 43 local table_concat = table.concat
45 local table_insert = table.insert 44 local table_insert = table.insert
46 local string_sub = string.sub 45 local string_sub = string.sub
921 _closelist[ handler ] = nil; 920 _closelist[ handler ] = nil;
922 end 921 end
923 _currenttime = luasocket_gettime( ) 922 _currenttime = luasocket_gettime( )
924 923
925 -- Check for socket timeouts 924 -- Check for socket timeouts
926 local difftime = os_difftime( _currenttime - _starttime ) 925 if _currenttime - _starttime > _checkinterval then
927 if difftime > _checkinterval then
928 _starttime = _currenttime 926 _starttime = _currenttime
929 for handler, timestamp in pairs( _writetimes ) do 927 for handler, timestamp in pairs( _writetimes ) do
930 if os_difftime( _currenttime - timestamp ) > _sendtimeout then 928 if _currenttime - timestamp > _sendtimeout then
931 handler.disconnect( )( handler, "send timeout" ) 929 handler.disconnect( )( handler, "send timeout" )
932 handler:force_close() -- forced disconnect 930 handler:force_close() -- forced disconnect
933 end 931 end
934 end 932 end
935 for handler, timestamp in pairs( _readtimes ) do 933 for handler, timestamp in pairs( _readtimes ) do
936 if os_difftime( _currenttime - timestamp ) > _readtimeout then 934 if _currenttime - timestamp > _readtimeout then
937 if not(handler.onreadtimeout) or handler:onreadtimeout() ~= true then 935 if not(handler.onreadtimeout) or handler:onreadtimeout() ~= true then
938 handler.disconnect( )( handler, "read timeout" ) 936 handler.disconnect( )( handler, "read timeout" )
939 handler:close( ) -- forced disconnect? 937 handler:close( ) -- forced disconnect?
940 else 938 else
941 _readtimes[ handler ] = _currenttime -- reset timer 939 _readtimes[ handler ] = _currenttime -- reset timer