Commit 7603e01a498c4f81dafbe5cd1b7efb8b210bd5f7

Authored by Grzegorz Jabłoński
1 parent 6df4a4a7

Fixed connection lifetime issue

Showing 1 changed file with 5 additions and 1 deletions
13-daytime8.cpp
@@ -38,10 +38,14 @@ public: @@ -38,10 +38,14 @@ public:
38 void start() { 38 void start() {
39 message_ = make_daytime_string(); 39 message_ = make_daytime_string();
40 asio::async_write(socket_, asio::buffer(message_), 40 asio::async_write(socket_, asio::buffer(message_),
41 - std::bind(&tcp_connection::handle_write, this, 41 + std::bind(&tcp_connection::handle_write, shared_from_this(),
42 std::placeholders::_1, std::placeholders::_2)); 42 std::placeholders::_1, std::placeholders::_2));
43 } 43 }
44 44
  45 + ~tcp_connection()
  46 + {
  47 + std::cout << "~tcp_connection()" << std::endl;
  48 + }
45 private: 49 private:
46 tcp_connection(asio::io_context &io_context) : socket_(io_context) {} 50 tcp_connection(asio::io_context &io_context) : socket_(io_context) {}
47 51