Software /
code /
prosody
Comparison
net/server_select.lua @ 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 |
parent | 5484:17ce73907c48 |
child | 5486:bcf27dbef6c6 |
comparison
equal
deleted
inserted
replaced
5484:17ce73907c48 | 5485:5147eed0a42e |
---|---|
844 handler.disconnect( )( handler, err ) | 844 handler.disconnect( )( handler, err ) |
845 handler:force_close() -- forced disconnect | 845 handler:force_close() -- forced disconnect |
846 _closelist[ handler ] = nil; | 846 _closelist[ handler ] = nil; |
847 end | 847 end |
848 _currenttime = luasocket_gettime( ) | 848 _currenttime = luasocket_gettime( ) |
849 | |
850 local difftime = os_difftime( _currenttime - _starttime ) | |
851 if difftime > _checkinterval then | |
852 _starttime = _currenttime | |
853 for handler, timestamp in pairs( _writetimes ) do | |
854 if os_difftime( _currenttime - timestamp ) > _sendtimeout then | |
855 --_writetimes[ handler ] = nil | |
856 handler.disconnect( )( handler, "send timeout" ) | |
857 handler:force_close() -- forced disconnect | |
858 end | |
859 end | |
860 for handler, timestamp in pairs( _readtimes ) do | |
861 if os_difftime( _currenttime - timestamp ) > _readtimeout then | |
862 --_readtimes[ handler ] = nil | |
863 handler.disconnect( )( handler, "read timeout" ) | |
864 handler:close( ) -- forced disconnect? | |
865 end | |
866 end | |
867 end | |
868 | |
849 if _currenttime - _timer >= math_min(next_timer_time, 1) then | 869 if _currenttime - _timer >= math_min(next_timer_time, 1) then |
850 next_timer_time = math_huge; | 870 next_timer_time = math_huge; |
851 for i = 1, _timerlistlen do | 871 for i = 1, _timerlistlen do |
852 local t = _timerlist[ i ]( _currenttime ) -- fire timers | 872 local t = _timerlist[ i ]( _currenttime ) -- fire timers |
853 if t then next_timer_time = math_min(next_timer_time, t); end | 873 if t then next_timer_time = math_min(next_timer_time, t); end |
919 use "setmetatable" ( _writetimes, { __mode = "k" } ) | 939 use "setmetatable" ( _writetimes, { __mode = "k" } ) |
920 | 940 |
921 _timer = luasocket_gettime( ) | 941 _timer = luasocket_gettime( ) |
922 _starttime = luasocket_gettime( ) | 942 _starttime = luasocket_gettime( ) |
923 | 943 |
924 addtimer( function( ) | |
925 local difftime = os_difftime( _currenttime - _starttime ) | |
926 if difftime > _checkinterval then | |
927 _starttime = _currenttime | |
928 for handler, timestamp in pairs( _writetimes ) do | |
929 if os_difftime( _currenttime - timestamp ) > _sendtimeout then | |
930 --_writetimes[ handler ] = nil | |
931 handler.disconnect( )( handler, "send timeout" ) | |
932 handler:force_close() -- forced disconnect | |
933 end | |
934 end | |
935 for handler, timestamp in pairs( _readtimes ) do | |
936 if os_difftime( _currenttime - timestamp ) > _readtimeout then | |
937 --_readtimes[ handler ] = nil | |
938 handler.disconnect( )( handler, "read timeout" ) | |
939 handler:close( ) -- forced disconnect? | |
940 end | |
941 end | |
942 end | |
943 end | |
944 ) | |
945 | |
946 local function setlogger(new_logger) | 944 local function setlogger(new_logger) |
947 local old_logger = log; | 945 local old_logger = log; |
948 if new_logger then | 946 if new_logger then |
949 log = new_logger; | 947 log = new_logger; |
950 end | 948 end |