Hi, Indrek.
// m_socket was associated with m_service m_socket->cancel(); m_socket->shutdown( boost::asio::ip::tcp::socket::shutdown_both, ec ); m_socket->close( ec ); delete m_socket; m_socket = NULL;
// Delete work on the service delete m_work; m_work = NULL;
// Stop the service m_service->stop();
// Join the thread this service was running on m_thread->interrupt(); m_thread->join(); delete m_thread; m_thread = NULL;
// Crashes here delete m_service; m_service = NULL;
Here's what VC10 reported: Access violation camc.exe!boost::asio::detail::socket_ops::send(unsigned int s, const _WSABUF * bufs, unsigned int count, int flags, boost::system::error_code & ec) Line 876 + 0x24 bytes C++ camc.exe!boost::asio::detail::socket_select_interrupter::interrupt() Line 127 + 0x18 bytes C++ camc.exe!boost::asio::detail::select_reactor::shutdown_service() Line 73 C++ camc.exe!boost::asio::detail::service_registry::~service_registry() Line 42 + 0xf bytes C++ camc.exe!boost::asio::detail::service_registry::`scalar deleting destructor'() + 0x16 bytes C++ camc.exe!boost::asio::io_service::~io_service() Line 51 + 0x1f bytes C++ camc.exe!boost::asio::io_service::`scalar deleting destructor'() + 0x16 bytes C++
May be the source of your problem is located in yours async write completion handler (it is often so - see asio-users mailing list). It seems that your completion handler tries to use destroyed m_socket. Regards, Marat Abrarov.