diff options
Diffstat (limited to 'server.cpp')
-rw-r--r-- | server.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -20,6 +20,7 @@ #include <boost/config.hpp> #include <exception> +#include <functional> #include <iostream> #include <thread> #include <vector> @@ -39,6 +40,10 @@ using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> const std::string Server::VersionString{ "Reichwein.IT Webserver "s + std::string{VERSION} }; +namespace { + const int32_t stats_timer_seconds { 24 * 60 * 60 }; // save stats once a day +} // anonymous namespace + Server::Server(Config& config, boost::asio::io_context& ioc, const Socket& socket, plugins_container_type& plugins, Statistics& statistics) : m_config(config) , m_ioc(ioc) @@ -66,6 +71,16 @@ int run_server(Config& config, plugins_container_type& plugins) ioc.stop(); }); + // Save stats once a day + boost::asio::steady_timer stats_save_timer(ioc, boost::asio::chrono::seconds(stats_timer_seconds)); + std::function<void(const boost::system::error_code&)> stats_callback = + [&](const boost::system::error_code& error){ + stats.save(); + stats_save_timer.expires_at(stats_save_timer.expires_at() + boost::asio::chrono::seconds(stats_timer_seconds)); + stats_save_timer.async_wait(stats_callback); + }; + stats_save_timer.async_wait(stats_callback); + std::vector<std::shared_ptr<Server>> servers; const auto& sockets {config.Sockets()}; |