# HG changeset patch # User Link Mauve # Date 1769778533 -3600 # Node ID d649d011df457fbf8a8d44b281b80ce7b43c6d08 # Parent c83aee2a0b11c362fde1c8cf178c3669e49f7d66 Use util.time.now() consistently instead of socket.gettime() diff -r c83aee2a0b11 -r d649d011df45 core/sessionmanager.lua --- a/core/sessionmanager.lua Fri Feb 13 16:19:12 2026 +0100 +++ b/core/sessionmanager.lua Fri Jan 30 14:08:53 2026 +0100 @@ -24,7 +24,7 @@ local sessionlib = require "prosody.util.session"; local initialize_filters = require "prosody.util.filters".initialize; -local gettime = require "socket".gettime; +local time_now = require "prosody.util.time".now; local _ENV = nil; -- luacheck: std none @@ -35,7 +35,7 @@ sessionlib.set_logger(session); sessionlib.set_conn(session, conn); - session.conntime = gettime(); + session.conntime = time_now(); local filter = initialize_filters(session); local w = conn.write; diff -r c83aee2a0b11 -r d649d011df45 net/dns.lua --- a/net/dns.lua Fri Feb 13 16:19:12 2026 +0100 +++ b/net/dns.lua Fri Jan 30 14:08:53 2026 +0100 @@ -16,6 +16,7 @@ local have_timer, timer = pcall(require, "prosody.util.timer"); local new_ip = require "prosody.util.ip".new_ip; local have_util_net, util_net = pcall(require, "prosody.util.net"); +local time_now = require "prosody.util.time".now; local log = require "prosody.util.logger".init("dns"); @@ -237,7 +238,7 @@ local function prune(rrs, time, soft) -- - - - - - - - - - - - - - - prune - time = time or socket.gettime(); + time = time or time_now(); for i,rr in ipairs(rrs) do if rr.tod then if rr.tod < time then @@ -300,7 +301,7 @@ local cache_metatable = {}; -- - - - - - - - - - - - - - - - cache_metatable function cache_metatable.__tostring(cache) - local time = socket.gettime(); + local time = time_now(); local t = {}; for class,types in pairs(cache) do for type,names in pairs(types) do @@ -318,7 +319,7 @@ function dns.random(...) -- - - - - - - - - - - - - - - - - - - dns.random - math.randomseed(math.floor(10000*socket.gettime()) % 0x80000000); + math.randomseed(math.floor(10000 * time_now()) % 0x80000000); dns.random = math.random; return dns.random(...); end @@ -813,7 +814,7 @@ if not (rrs and rrs[1]) then return end return self:peek(rrs[1].cname, qtype, qclass, n - 1); end - if prune(rrs, socket.gettime()) and qtype == '*' or not next(rrs) then + if prune(rrs, time_now()) and qtype == '*' or not next(rrs) then set(self.cache, qclass, qtype, qname, nil); return nil; end @@ -824,7 +825,7 @@ function resolver:purge(soft) -- - - - - - - - - - - - - - - - - - - purge if soft == 'soft' then - self.time = socket.gettime(); + self.time = time_now(); for class,types in pairs(self.cache or {}) do for type,names in pairs(types) do for name,rrs in pairs(names) do @@ -859,7 +860,7 @@ packet = header..question, server = self.best_server, delay = 1, - retry = socket.gettime() + self.delays[1]; + retry = time_now() + self.delays[1]; qclass = qclass; qtype = qtype; qname = qname; @@ -914,7 +915,7 @@ sock = self:voidsocket(sock); -- Find all requests to the down server, and retry on the next server - self.time = socket.gettime(); + self.time = time_now(); log("debug", "servfail %d (of %d)", num, #self.server); for id,queries in pairs(self.active) do for question,o in pairs(queries) do @@ -970,7 +971,7 @@ function resolver:receive(rset) -- - - - - - - - - - - - - - - - - receive --print('receive'); print(self.socket); - self.time = socket.gettime(); + self.time = time_now(); rset = rset or self.socket; local response; @@ -1019,7 +1020,7 @@ function resolver:feed(sock, packet, force) --print('receive'); print(self.socket); - self.time = socket.gettime(); + self.time = time_now(); local response = self:decode(packet, force); if response and self.active[response.header.id] @@ -1072,7 +1073,7 @@ while self:receive() do end if not next(self.active) then return nil; end - self.time = socket.gettime(); + self.time = time_now(); for id,queries in pairs(self.active) do for question,o in pairs(queries) do if self.time >= o.retry then diff -r c83aee2a0b11 -r d649d011df45 net/server_event.lua --- a/net/server_event.lua Fri Feb 13 16:19:12 2026 +0100 +++ b/net/server_event.lua Fri Jan 30 14:08:53 2026 +0100 @@ -54,8 +54,7 @@ local inet_pton = inet.pton; local sslconfig = require "prosody.util.sslconfig"; local tls_impl = require "prosody.net.tls_luasec"; - -local socket_gettime = socket.gettime +local time_now = require "prosody.util.time".now; local log = require ("prosody.util.logger").init("socket") @@ -521,7 +520,7 @@ local interface = { type = "client"; conn = client; - currenttime = socket_gettime( ); -- safe the origin + currenttime = time_now(); -- safe the origin writebuffer = {}; -- writebuffer writebufferlen = 0; -- length of writebuffer send = client.send; -- caching table lookups @@ -918,7 +917,7 @@ local function add_task(delay, callback) local event_handle; event_handle = base:addevent(nil, 0, function () - local ret = callback(socket_gettime()); + local ret = callback(time_now()); if ret then return 0, ret; elseif event_handle then diff -r c83aee2a0b11 -r d649d011df45 net/server_select.lua --- a/net/server_select.lua Fri Feb 13 16:19:12 2026 +0100 +++ b/net/server_select.lua Fri Jan 30 14:08:53 2026 +0100 @@ -48,7 +48,7 @@ --// extern libs //-- local luasocket = use "socket" or require "socket" -local luasocket_gettime = luasocket.gettime +local time_now = require "prosody.util.time".now; local inet = require "prosody.util.net"; local inet_pton = inet.pton; local sslconfig = require "prosody.util.sslconfig"; @@ -919,7 +919,7 @@ local new_data = {}; function add_task(delay, callback) - local current_time = luasocket_gettime(); + local current_time = time_now(); delay = delay + current_time; if delay >= current_time then table_insert(new_data, {delay, callback}); @@ -970,7 +970,7 @@ loop = function(once) -- this is the main loop of the program if quitting then return "quitting"; end if once then quitting = "once"; end - _currenttime = luasocket_gettime( ) + _currenttime = time_now(); repeat -- Fire timers local next_timer_time = math_huge; @@ -1003,7 +1003,7 @@ handler:force_close() -- forced disconnect _closelist[ handler ] = nil; end - _currenttime = luasocket_gettime( ) + _currenttime = time_now(); -- Check for socket timeouts if _currenttime - _starttime > _checkinterval then @@ -1151,7 +1151,7 @@ use "setmetatable" ( _readtimes, { __mode = "k" } ) use "setmetatable" ( _writetimes, { __mode = "k" } ) -_starttime = luasocket_gettime( ) +_starttime = time_now(); local function setlogger(new_logger) local old_logger = log; diff -r c83aee2a0b11 -r d649d011df45 util/adminstream.lua --- a/util/adminstream.lua Fri Feb 13 16:19:12 2026 +0100 +++ b/util/adminstream.lua Fri Jan 30 14:08:53 2026 +0100 @@ -1,7 +1,7 @@ local st = require "prosody.util.stanza"; local new_xmpp_stream = require "prosody.util.xmppstream".new; local sessionlib = require "prosody.util.session"; -local gettime = require "prosody.util.time".now; +local time_now = require "prosody.util.time".now; local runner = require "prosody.util.async".runner; local add_task = require "prosody.util.timer".add_task; local events = require "prosody.util.events"; @@ -197,7 +197,7 @@ sessionlib.set_logger(session); sessionlib.set_conn(session, conn); - session.conntime = gettime(); + session.conntime = time_now(); session.type = "admin"; local stream = new_xmpp_stream(session, stream_callbacks); diff -r c83aee2a0b11 -r d649d011df45 util/throttle.lua --- a/util/throttle.lua Fri Feb 13 16:19:12 2026 +0100 +++ b/util/throttle.lua Fri Jan 30 14:08:53 2026 +0100 @@ -1,5 +1,5 @@ -local gettime = require "prosody.util.time".now +local time_now = require "prosody.util.time".now; local setmetatable = setmetatable; local _ENV = nil; @@ -9,7 +9,7 @@ local throttle_mt = { __index = throttle }; function throttle:update() - local newt = gettime(); + local newt = time_now(); local elapsed = newt - self.t; self.t = newt; local balance = (self.rate * elapsed) + self.balance; @@ -40,7 +40,7 @@ end local function create(max, period) - return setmetatable({ rate = max / period, max = max, t = gettime(), balance = max }, throttle_mt); + return setmetatable({ rate = max / period, max = max, t = time_now(), balance = max }, throttle_mt); end return {