summaryrefslogtreecommitdiffhomepage
path: root/whiteboard.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'whiteboard.cpp')
-rw-r--r--whiteboard.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/whiteboard.cpp b/whiteboard.cpp
index 2c8a47b..88f4f3b 100644
--- a/whiteboard.cpp
+++ b/whiteboard.cpp
@@ -104,6 +104,13 @@ public:
{
}
+ ~session()
+ {
+ if (m_stats_timer)
+ m_stats_timer->cancel();
+ m_stats_timer = nullptr;
+ }
+
void do_read_handshake()
{
// Set a decorator to change the Server of the handshake
@@ -273,13 +280,15 @@ public:
void stats_callback(const boost::system::error_code&)
{
- auto data{std::make_shared<std::string>(stats_xml())};
- auto buffer{std::make_shared<boost::asio::const_buffer>(data->data(), data->size())};
- m_ws->async_write(*buffer, boost::asio::bind_executor(m_ws->next_layer().get_executor(),
- boost::beast::bind_front_handler(&session::on_write_stats, shared_from_this(), data, buffer)));
+ if (m_stats_timer) {
+ auto data{std::make_shared<std::string>(stats_xml())};
+ auto buffer{std::make_shared<boost::asio::const_buffer>(data->data(), data->size())};
+ m_ws->async_write(*buffer, boost::asio::bind_executor(m_ws->next_layer().get_executor(),
+ boost::beast::bind_front_handler(&session::on_write_stats, shared_from_this(), data, buffer)));
- m_stats_timer->expires_at(m_stats_timer->expires_at() + boost::asio::chrono::seconds(5));
- m_stats_timer->async_wait(boost::beast::bind_front_handler(&session::stats_callback, this));
+ m_stats_timer->expires_at(m_stats_timer->expires_at() + boost::asio::chrono::seconds(5));
+ m_stats_timer->async_wait(boost::beast::bind_front_handler(&session::stats_callback, this));
+ }
}
void setup_stats_timer()