Dale Wilson
2012-11-08 22:36:24 UTC
void server::handle_accept(const boost::system::error_code& e)
{
if (!e)
{
// Start first connection
new_connection_->start();
// Create second connection
new_connection_.reset(new connection(io_service_, request_handler_));
acceptor_.async_accept(new_connection_->socket(),
boost::bind(&server::handle_accept, this,
boost::asio::placeholders::error));
}
}
The problem is: the "second" connection is constructed but never
destroyed; i.e. when io_service_.stop() is called, the thread exits
properly but the destructor of the second connection is never called.
I have verified this by placing debug statements in the destructor.
What do I need to do to get the destructor of the second (non-started)
connection to be called when io_service_.stop() is called?
Either call{
if (!e)
{
// Start first connection
new_connection_->start();
// Create second connection
new_connection_.reset(new connection(io_service_, request_handler_));
acceptor_.async_accept(new_connection_->socket(),
boost::bind(&server::handle_accept, this,
boost::asio::placeholders::error));
}
}
The problem is: the "second" connection is constructed but never
destroyed; i.e. when io_service_.stop() is called, the thread exits
properly but the destructor of the second connection is never called.
I have verified this by placing debug statements in the destructor.
What do I need to do to get the destructor of the second (non-started)
connection to be called when io_service_.stop() is called?
new_connection_.reset();
after io_service.stop();
Or don't worry about it. The second object will be destroyed when your server
object is destroyed.
Dale