In the connection object at the boost asio HTTP server example in methods do_read
and do_write
the shared_from_this()
is captured to address the connection object lifespan issue, as been answered previously. It is still not clear why on lines 67 and 88 the code calls shared_from_this()
again, instead of using self
:
40 auto self(shared_from_this());
41 socket_.async_read_some(boost::asio::buffer(buffer_),
42 [this, self](boost::system::error_code ec, std::size_t bytes_transferred)
43 {
....
67 connection_manager_.stop(shared_from_this());
```