On 04/05/2017 10:32 PM, Christopher Pisz via Boost-users wrote:
The problem I have with this example listing is that it cheats and it cheats big, by making the tcp_connection a shared_ptr, such that it doesn't worry about the lifetime management of each connection.
That is not cheating.
Consider we'd have a callstack that looked something like this: tcp_connection::~tcp_connection tcp_server::OnDisconnect tcp_connection::OnDisconnect tcp_connection::Disconnect
If Disconnect is an asynchronous operation, then it should not call OnDisconnect directly. You can post it on the io_service instead.
I imagine everyone doing server programming comes across this scenario in some fashion. What is a strategy for handling it?
Preferably shared_ptr, or io_service::post() if for some reason you cannot use shared_ptr, e.g. if the object has to be destroyed by a a specific thread.