boost::asio::io_service - cancel posted work

I posted an async_accept to my io_service. The async_accept gets posted again to listen for incoming connections every time it completes. I was under the impression that calling io_service::stop, would be the way to stop listening. When debugging, I see that a function object was created when I called bind inside my async_accept call. That function object contains a smart pointer to the instance of the object to whom the method to call back belongs. Since the callback never happens, my instance never gets destroyed. How do I effectively cancel any outstanding work the io_service has posted to it, such that the smart pointer in the function object that the bind created will lose its reference count? In debugging, the callback never gets called after stop, not does the reference count in the smart pointer decrement.

Christopher Pisz
I posted an async_accept to my io_service. The async_accept gets posted again to listen for incoming connections every time it completes.
I was under the impression that calling io_service::stop, would be the way to stop listening.
When debugging, I see that a function object was created when I called bind inside my async_accept call.
That function object contains a smart pointer to the instance of the object
to
whom the method to call back belongs.
Since the callback never happens, my instance never gets destroyed.
How do I effectively cancel any outstanding work the io_service has posted to it, such that the smart pointer in the function object that the bind created will lose its reference count?
In debugging, the callback never gets called after stop, not does the reference count in the smart pointer decrement.
------------------------------
Here is the sequence of events:
void TcpListener::Listen()
{
// Bind function callbacks that the connection will communicate to us with
//
// Important: These cannot be shared pointers, because the bind call
actually
// creates an object that stores the pointer. Since these
callbacks
// are stored in the connection object, it would create a
reference
// count that would never go away
//
TcpServerSideConnection::AcceptCompleteListenerCallback acceptCallback =
boost::bind(&TcpListener::OnAcceptComplete, this,
boost::asio::placeholders::error, _2);
TcpServerSideConnection::ConnectionClosedListenerCallback
connectionClosedCallback =
boost::bind(&TcpListener::OnConnectionClosed, this, _1);
TcpServerSideConnection::ReadPayloadUTF8CompleteListenerCallback
readPayloadUTF8Callback =
boost::bind(&TcpListener::OnReadPayloadUTF8Complete, this, _1, _2);
// Create a connection to be accepted
TcpServerSideConnection::SmartPtr newConnection =
TcpServerSideConnection::Create(ioService_,
acceptCallback,
connectionClosedCallback,
readPayloadUTF8Callback);
// Let the connection itself issue the async accept, so that it may manage
its internal state.
// It will call us back if successfully accepted a connection request
newConnection->Accept(acceptor_);
}
void TcpServerSideConnection::Accept(boost::asio::ip::tcp::acceptor & acceptor)
{
// Close if open
Close();
// Change state to reflect are posting the request to connect for io
completion
state_ = CONNECTING;
// Make the async call
TcpServerSideConnection::SmartPtr me =
boost::dynamic_pointer_cast
participants (1)
-
Christopher Pisz