close files of inactive tranfsers

This commit is contained in:
Green Sky
2025-03-14 13:50:30 +01:00
parent 246587e30d
commit f5f7f2ca9d
10 changed files with 85 additions and 25 deletions

View File

@@ -0,0 +1,33 @@
#include "./file_inactivity_system.hpp"
#include <solanaceae/object_store/object_store.hpp>
#include <solanaceae/file/file2.hpp>
#include "./components.hpp"
#include <iostream>
namespace Systems {
void file_inactivity(
ObjectRegistry& os_reg,
float current_time
) {
std::vector<Object> to_close;
size_t total {0};
os_reg.view<Components::FT1File2>().each([&os_reg, &to_close, &total, current_time](Object ov, const Components::FT1File2& ft_f) {
if (current_time - ft_f.last_activity_ts >= 30.f) {
// after 30sec of inactivity
to_close.push_back(ov);
}
total++;
});
if (!to_close.empty()) {
std::cout << "SHA1_NGCFT1: closing " << to_close.size() << " out of " << total << " open files\n";
os_reg.remove<Components::FT1File2>(to_close.cbegin(), to_close.cend());
}
}
} // Systems