What happens to completion handlers when socket is shutdown/closed and then deleted (that is destructor is run and memory released)? AFAIK after socked it closed all completion handlers will receive error code next time even loop is polled. But what happens if the socked is deleted before even handlers had a chance to run? Is it OK to delete socket before dispatching event handlers?
What happens to completion handlers when socket is shutdown/closed and then deleted (that is
Share
All handlers is guaranteed to be called. If socket was closed – handlers will be called with some error code.
Normally, you need to use this guarantee to control lifetime of your objects using boost::enable_shared_from_this.
With this approach, your socket object will outlive all pending handlers.