comparison net/server_select.lua @ 14078:d649d011df45

Use util.time.now() consistently instead of socket.gettime()
author Link Mauve <linkmauve@linkmauve.fr>
date Fri, 30 Jan 2026 14:08:53 +0100
parents a4c47203a9eb
children
comparison
equal deleted inserted replaced
14077:c83aee2a0b11 14078:d649d011df45
46 local coroutine_yield = coroutine.yield 46 local coroutine_yield = coroutine.yield
47 47
48 --// extern libs //-- 48 --// extern libs //--
49 49
50 local luasocket = use "socket" or require "socket" 50 local luasocket = use "socket" or require "socket"
51 local luasocket_gettime = luasocket.gettime 51 local time_now = require "prosody.util.time".now;
52 local inet = require "prosody.util.net"; 52 local inet = require "prosody.util.net";
53 local inet_pton = inet.pton; 53 local inet_pton = inet.pton;
54 local sslconfig = require "prosody.util.sslconfig"; 54 local sslconfig = require "prosody.util.sslconfig";
55 local has_luasec, tls_impl = pcall(require, "prosody.net.tls_luasec"); 55 local has_luasec, tls_impl = pcall(require, "prosody.net.tls_luasec");
56 56
917 local add_task do 917 local add_task do
918 local data = {}; 918 local data = {};
919 local new_data = {}; 919 local new_data = {};
920 920
921 function add_task(delay, callback) 921 function add_task(delay, callback)
922 local current_time = luasocket_gettime(); 922 local current_time = time_now();
923 delay = delay + current_time; 923 delay = delay + current_time;
924 if delay >= current_time then 924 if delay >= current_time then
925 table_insert(new_data, {delay, callback}); 925 table_insert(new_data, {delay, callback});
926 else 926 else
927 local r = callback(current_time); 927 local r = callback(current_time);
968 end 968 end
969 969
970 loop = function(once) -- this is the main loop of the program 970 loop = function(once) -- this is the main loop of the program
971 if quitting then return "quitting"; end 971 if quitting then return "quitting"; end
972 if once then quitting = "once"; end 972 if once then quitting = "once"; end
973 _currenttime = luasocket_gettime( ) 973 _currenttime = time_now();
974 repeat 974 repeat
975 -- Fire timers 975 -- Fire timers
976 local next_timer_time = math_huge; 976 local next_timer_time = math_huge;
977 for i = 1, _timerlistlen do 977 for i = 1, _timerlistlen do
978 local t = _timerlist[ i ]( _currenttime ) -- fire timers 978 local t = _timerlist[ i ]( _currenttime ) -- fire timers
1001 for handler, err in pairs( _closelist ) do 1001 for handler, err in pairs( _closelist ) do
1002 handler.disconnect( )( handler, err ) 1002 handler.disconnect( )( handler, err )
1003 handler:force_close() -- forced disconnect 1003 handler:force_close() -- forced disconnect
1004 _closelist[ handler ] = nil; 1004 _closelist[ handler ] = nil;
1005 end 1005 end
1006 _currenttime = luasocket_gettime( ) 1006 _currenttime = time_now();
1007 1007
1008 -- Check for socket timeouts 1008 -- Check for socket timeouts
1009 if _currenttime - _starttime > _checkinterval then 1009 if _currenttime - _starttime > _checkinterval then
1010 _starttime = _currenttime 1010 _starttime = _currenttime
1011 for handler, timestamp in pairs( _writetimes ) do 1011 for handler, timestamp in pairs( _writetimes ) do
1149 1149
1150 use "setmetatable" ( _socketlist, { __mode = "k" } ) 1150 use "setmetatable" ( _socketlist, { __mode = "k" } )
1151 use "setmetatable" ( _readtimes, { __mode = "k" } ) 1151 use "setmetatable" ( _readtimes, { __mode = "k" } )
1152 use "setmetatable" ( _writetimes, { __mode = "k" } ) 1152 use "setmetatable" ( _writetimes, { __mode = "k" } )
1153 1153
1154 _starttime = luasocket_gettime( ) 1154 _starttime = time_now();
1155 1155
1156 local function setlogger(new_logger) 1156 local function setlogger(new_logger)
1157 local old_logger = log; 1157 local old_logger = log;
1158 if new_logger then 1158 if new_logger then
1159 log = new_logger; 1159 log = new_logger;