Skip to content

Commit 4aa242c

Browse files
committed
protect m_accepter.reset by lock in linux_http_server
1 parent 183d8ab commit 4aa242c

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Release/src/http/listener/http_linux_server.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,13 @@ void hostport_listener::on_accept(ip::tcp::socket* socket, const boost::system::
8989
pplx::scoped_lock<pplx::extensibility::recursive_lock_t> lock(m_connections_lock);
9090
m_connections.insert(new connection(std::unique_ptr<tcp::socket>(std::move(socket)), m_p_server, this));
9191
m_all_connections_complete.reset();
92-
}
93-
94-
{
95-
// spin off another async accept
96-
auto newSocket = new ip::tcp::socket(crossplat::threadpool::shared_instance().service());
97-
m_acceptor->async_accept(*newSocket, boost::bind(&hostport_listener::on_accept, this, newSocket, placeholders::error));
92+
93+
if (m_acceptor)
94+
{
95+
// spin off another async accept
96+
auto newSocket = new ip::tcp::socket(crossplat::threadpool::shared_instance().service());
97+
m_acceptor->async_accept(*newSocket, boost::bind(&hostport_listener::on_accept, this, newSocket, placeholders::error));
98+
}
9899
}
99100

100101
}
@@ -554,11 +555,11 @@ void connection::finish_request_response()
554555

555556
void hostport_listener::stop()
556557
{
557-
m_acceptor.reset();
558558

559559
// halt existing connections
560560
{
561561
pplx::scoped_lock<pplx::extensibility::recursive_lock_t> lock(m_connections_lock);
562+
m_acceptor.reset();
562563
for (auto it = m_connections.begin(); it != m_connections.end(); ++it)
563564
{
564565
(*it)->close();

0 commit comments

Comments
 (0)