Boost logo

Boost Users :

Subject: Re: [Boost-users] AsIO daytime example needs terminate code
From: Christopher Yeleighton (giecrilj_at_[hidden])
Date: 2010-04-29 09:06:48


Christopher Yeleighton <giecrilj <at> stegny.2a.pl> writes:

> May I call socket::cancel in a signal handler?

Rather acceptor::cancel; the idea is to cancel the listener in the signal
handler. May I?

> How do I dispose of the open session objects?

Calling io_session::stop does not cancel pending tasks, it just destroys them.
Therefore all cleanup code should be in the destructor of the session object and
thus the async TCP echo server example code is wrong.

Session objects are not of value type because they contain a socket, which is a
resource that cannot be copied. Therefore they cannot be passed by value. The
reference to a session objects must be a value type; boost::shared_ptr is well
suited for this task (std::auto_ptr is a resource type too). And indeed, the
async TCP daytime server example does use boost::shared_ptr; why the async TCP
echo server recourses to quirks like { if (error) delete this; } is beyond my
understanding. The example is misleading and should be fixed.

Chris


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