@ -40,15 +40,22 @@ end
-- Check if a TCP port is accepting connections within a timeout (seconds)
function network . port_is_up ( host , port , timeout_sec )
host = tostring ( host or " 127.0.0.1 " )
port = tonumber ( port or 0 ) or 0
local timeout = tonumber ( timeout_sec or 1 ) or 1
-- Set defaults with clear intent
host = host or " 127.0.0.1 "
port = port or 0
timeout_sec = timeout_sec or 30
-- Convert to proper types
host = tostring ( host )
port = tonumber ( port ) or 0
local timeout = tonumber ( timeout_sec ) or 30
if port <= 0 then return false end
-- Fallback to basic check if socket is not available
if not network.is_socket_available ( ) then
utils.log ( " Socket module not available, using basic port check " )
local cmd = string.format ( " nc -z -w1 %s %d 2>/dev/null " , host , port )
utils.log ( " Socket module not available, using basic port check with " .. timeout .. " s timeout " )
local cmd = string.format ( " nc -z -w%d %s %d 2>/dev/null " , timeout , host , port )
local result = os.execute ( cmd )
return result == 0
end