fix(network): call accept on NetworkServer initialization and after player addition

- Ensure `accept` is called during `NetworkServer` initialization and after successfully adding a player to handle new connections continuously.
This commit is contained in:
Kieran Kihn
2025-11-29 18:51:41 +08:00
parent b6144d33e9
commit 12d1d6c93f

View File

@@ -60,6 +60,7 @@ namespace UNO::NETWORK {
this->acceptor_.async_accept([this](const asio::error_code &ec, asio::ip::tcp::socket socket) { this->acceptor_.async_accept([this](const asio::error_code &ec, asio::ip::tcp::socket socket) {
if (!ec) { if (!ec) {
this->addPlayer(std::move(socket)); this->addPlayer(std::move(socket));
accept();
} }
}); });
} }
@@ -67,6 +68,7 @@ namespace UNO::NETWORK {
NetworkServer::NetworkServer(uint16_t port, std::function<void(size_t, std::string)> callback) : NetworkServer::NetworkServer(uint16_t port, std::function<void(size_t, std::string)> callback) :
acceptor_(io_context_, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), port)), playerCount(0), callback_(std::move(callback)) acceptor_(io_context_, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), port)), playerCount(0), callback_(std::move(callback))
{ {
accept();
} }
void NetworkServer::addPlayer(asio::ip::tcp::socket socket) void NetworkServer::addPlayer(asio::ip::tcp::socket socket)