Skip to content

Commit 6a1dccc

Browse files
committed
corrects an infinite loop when the acceptor is closed in thread pool mode references #168
1 parent 6aa11a7 commit 6a1dccc

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/roles/server.hpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,14 @@ void server<endpoint>::start_listen(const boost::asio::ip::tcp::endpoint& e,size
309309
template <class endpoint>
310310
void server<endpoint>::stop_listen(bool join) {
311311
{
312-
boost::unique_lock<boost::recursive_mutex> lock(m_endpoint.m_lock);
313-
314-
if (m_state != LISTENING) {
315-
throw exception("stop_listen called from invalid state");
316-
}
317-
318-
m_acceptor.close();
319-
}
312+
boost::unique_lock<boost::recursive_mutex> lock(m_endpoint.m_lock);
313+
314+
if (m_state != LISTENING) {
315+
throw exception("stop_listen called from invalid state");
316+
}
317+
318+
m_acceptor.close();
319+
}
320320

321321
m_state = STOPPING;
322322

@@ -353,6 +353,13 @@ template <class endpoint>
353353
void server<endpoint>::start_accept() {
354354
boost::lock_guard<boost::recursive_mutex> lock(m_endpoint.m_lock);
355355

356+
if (!m_acceptor.is_open()) {
357+
m_endpoint.m_alog->at(log::alevel::ENDPOINT)
358+
<< "Accept loop is stopping because acceptor was closed."
359+
<< log::endl;
360+
return;
361+
}
362+
356363
connection_ptr con = m_endpoint.create_connection();
357364

358365
if (con == connection_ptr()) {
@@ -362,7 +369,7 @@ void server<endpoint>::start_accept() {
362369
<< log::endl;
363370
return;
364371
}
365-
372+
366373
m_acceptor.async_accept(
367374
con->get_raw_socket(),
368375
boost::bind(

0 commit comments

Comments
 (0)