Hi guys,
Picture a server class with the following methods (pseudocode):
void Server::Work()
{
// Start the Async receive.
mSocket.async_receive_from( *blah* ) );
// Start the Async IO service.
mASIOService.run();
}
void Server::Start()
{
// Launch a new thread to do the work.
mThread = boost::thread( boost::bind( &Server::Work, this ) );
}
void Server::Stop()
{
// Post the stop request to the io_service.
mASIOService.post( boost::bind( &Server::DoStop, this ) );
// Join the comms thread.
mThread.join();
}
void Server::DoStop()
{
// Actually stop the io_service.
mASIOService.stop();
}
Assuming handling of packets is all correctly implemented, is it safe for the user to simply call the Stop() object method to stop the server?
Basically, can a function that's been post()ed to an io_service call io_service.stop() for that io_service?
TIA,
Dom