From b0f8b28977e59b7fbfc1ce57ee5c102b8e4e0690 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 12 Feb 2023 11:54:05 +0100 Subject: Touch documents on read (i.e. reset timeout on read) --- whiteboard.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'whiteboard.cpp') 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& 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 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); -- cgit v1.2.3