util filter table
This commit is contained in:
@@ -66,22 +66,7 @@ txnctrl.new = function ()
|
||||
-- close timed-out transactions
|
||||
public.cleanup = function ()
|
||||
local now = util.time()
|
||||
|
||||
local move_to = 1
|
||||
for i = 1, public.length() do
|
||||
local txn = self.list[i]
|
||||
if txn ~= nil then
|
||||
if txn.expiry <= now then
|
||||
self.list[i] = nil
|
||||
else
|
||||
if self.list[move_to] == nil then
|
||||
self.list[move_to] = txn
|
||||
self.list[i] = nil
|
||||
end
|
||||
move_to = move_to + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
util.filter_table(self.list, function (txn) return txn.expiry > now end)
|
||||
end
|
||||
|
||||
-- clear the transaction list
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local log = require("scada-common.log")
|
||||
local mqueue = require("scada-common.mqueue")
|
||||
local util = require("scada-common.util")
|
||||
|
||||
local coordinator = require("supervisor.session.coordinator")
|
||||
local plc = require("supervisor.session.plc")
|
||||
@@ -99,22 +100,10 @@ end
|
||||
-- delete any closed sessions
|
||||
---@param sessions table
|
||||
local function _free_closed(sessions)
|
||||
local move_to = 1
|
||||
for i = 1, #sessions do
|
||||
local session = sessions[i] ---@type plc_session_struct
|
||||
if session ~= nil then
|
||||
if session.open then
|
||||
if sessions[move_to] == nil then
|
||||
sessions[move_to] = session
|
||||
sessions[i] = nil
|
||||
end
|
||||
move_to = move_to + 1
|
||||
else
|
||||
log.debug("free'ing closed session " .. session.instance.get_id() .. " on remote port " .. session.r_port)
|
||||
sessions[i] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
local f = function (session) return session.open end
|
||||
local on_delete = function (session) log.debug("free'ing closed session " .. session.instance.get_id() .. " on remote port " .. session.r_port) end
|
||||
|
||||
util.filter_table(sessions, f, on_delete)
|
||||
end
|
||||
|
||||
-- PUBLIC FUNCTIONS --
|
||||
|
||||
Reference in New Issue
Block a user