diff --git a/src/server/async/socket_server.cc b/src/server/async/socket_server.cc index 152d6ec5..ca48e71a 100644 --- a/src/server/async/socket_server.cc +++ b/src/server/async/socket_server.cc @@ -1720,14 +1720,19 @@ void SocketServer::Stop() { if (stopped_.exchange(true)) { return; } + // stop accepting further connections + this->Close(); std::lock_guard scope_lock(this->connections_mutex_); std::vector connection_ids_; for (auto& pair : connections_) { pair.second->Stop(); } + connections_.clear(); } +void SocketServer::Close() { closable_.store(true); } + bool SocketServer::ExistsConnection(int conn_id) const { std::lock_guard scope_lock(this->connections_mutex_); return connections_.find(conn_id) != connections_.end(); diff --git a/src/server/async/socket_server.h b/src/server/async/socket_server.h index e8ec8d08..63f8bd43 100644 --- a/src/server/async/socket_server.h +++ b/src/server/async/socket_server.h @@ -236,7 +236,7 @@ class SocketServer { * Cancel the "async_accept" action on the acceptor to stop accepting * further connections. */ - virtual void Close() { closable_.store(true); } + virtual void Close(); /** * Check if @conn_id@ exists in the connection pool.