diff --git a/src/roles/server.hpp b/src/roles/server.hpp index b50894b449..48f4ef9690 100644 --- a/src/roles/server.hpp +++ b/src/roles/server.hpp @@ -308,10 +308,16 @@ void server::start_listen(const boost::asio::ip::tcp::endpoint& e,size template void server::stop_listen(bool join) { - if (m_state != LISTENING) { - throw exception("stop_listen called from invalid state"); - } - + { + boost::unique_lock lock(m_endpoint.m_lock); + + if (m_state != LISTENING) { + throw exception("stop_listen called from invalid state"); + } + + m_acceptor.close(); + } + m_state = STOPPING; if(join) {