Boost logo

Boost Users :

Subject: Re: [Boost-users] [Asio]Question about error_code when socket::close
From: Boris Schaeling (boris_at_[hidden])
Date: 2010-05-17 12:13:19


On Mon, 17 May 2010 12:29:59 +0200, Comet <cometliao_at_[hidden]> wrote:

> [...]the question I asked emerges:
>
> void HandleRead(const boost::system::error_code& error,
> size_t bytes_transferred) {
> if (error)
> //should I erase shared_from_this() from session_set? this object
> may have been destroyed...
> }
>
> ....
> session->Close();
> session_set->erase(session); // session is destroyed here. if I don't
> do this here, where should I do ? HandleRead may not be registered
> ever...

Then you need to do reference counting yourself. You must count pending
asynchronous I/O operations and destroy the object when the counter is
decreased to 0. I don't think there is much else you can do?

Boris


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net