From: Christopher Kohlhoff (chris_at_[hidden])
Date: 2006-12-03 19:49:14


Hi Mathias,

On Sun, 03 Dec 2006 18:08:39 +0100, "Mathias Gaunard"
<mathias.gaunard_at_[hidden]> said:
> From the examples I have read, it seems session objects, which have a
> non-trivial lifetime, are allocated on the freestore and are then
> responsible of their own self-destruction.
>
> Not only do I find it weird to see "delete this" but also I'm a bit
> confused given that I like to use RAII everywhere.
> That approach also has the problem that if an exception occurs somewhere
> in the session, bubbling will never destroy the session object.

Hmm, I can only find two such unreconstructed examples. Most of the
examples (including the tutorial) now use shared_ptr and
enable_shared_from_this to manage the session object lifetimes. This is
the recommended approach.

> Actually there should be a session manager containing the sessions.
> Maybe it could be interesting to provide helper objects to help with
> that kind of stuff.
> What do you think?

If you use shared_ptr/enable_shared_from_this then the io_service is
essentially a session manager. If you interrupt() the io_service and
then destroy it, any handlers associated with unfinished operations will
be destroyed, which in turn means the session objects will be destroyed.

Cheers,
Chris