diff options
author | Roland Reichwein <mail@reichwein.it> | 2023-02-12 11:54:05 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2023-02-12 11:54:05 +0100 |
commit | b0f8b28977e59b7fbfc1ce57ee5c102b8e4e0690 (patch) | |
tree | 926eb8dbd140d84ab0238ce7d671673056f12f56 /whiteboard.cpp | |
parent | 7d5ca5cebfe3453aaa3c649bbc3e771e6d636ac9 (diff) |
Touch documents on read (i.e. reset timeout on read)
Diffstat (limited to 'whiteboard.cpp')
-rw-r--r-- | whiteboard.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/whiteboard.cpp b/whiteboard.cpp index 044321b..5424a79 100644 --- a/whiteboard.cpp +++ b/whiteboard.cpp @@ -448,6 +448,16 @@ void Whiteboard::on_accept(boost::system::error_code ec, boost::asio::ip::tcp::s do_accept(); } +// for long running connections, don't timeout them but touch associated ids +// regularly, at cleanup time +void Whiteboard::touch_all_connections() +{ + std::for_each(m_registry.begin(), m_registry.end(), [&](const std::pair<ConnectionRegistry::connection, std::string>& i) + { + m_storage->touchDocument(i.second); + }); +} + // the actual main() for testability int Whiteboard::run(int argc, char* argv[]) { @@ -502,6 +512,7 @@ int Whiteboard::run(int argc, char* argv[]) std::lock_guard<std::mutex> lock(m_storage_mutex); if (!m_storage) throw std::runtime_error("Storage not initialized"); + touch_all_connections(); m_storage->cleanup(); storage_cleanup_timer.expires_at(storage_cleanup_timer.expires_at() + boost::asio::chrono::hours(24)); storage_cleanup_timer.async_wait(storage_cleanup_callback); |