#pragma once #include #include #include class Connection; /** * @brief Watch for connection activity and disconnect on stall * * The thread will send a ping if no message is received in the * last TIMEOUT seconds. After another period of no messages * the thread will disconnect the connection. * */ class WatchdogThread : std::enable_shared_from_this { Connection& connection_; boost::asio::steady_timer timer_; /// @brief Set true and ping sent and false when reply received bool stalled_; const std::chrono::steady_clock::duration TIMEOUT = std::chrono::seconds{30}; /// @brief Start the timer /// @return auto start_timer(); /// @brief auto on_activity() -> void; /// @brief auto on_timeout() -> void; /// @brief callback for ConnectEvent event auto on_connect() -> void; /// @brief callback for DisconnectEvent event auto on_disconnect() -> void; public: WatchdogThread(Connection& connection); static auto start(Connection& connection) -> void; };