From a47e120ff48d093e36963841c1ebe09e318503f0 Mon Sep 17 00:00:00 2001 From: Salanto <62221668+Salanto@users.noreply.github.com> Date: Thu, 9 Jun 2022 11:00:43 +0200 Subject: [PATCH] Resolve parenting issues This should FINALLY resolve the QIODevice errors as closing the socket now lets Qt handle all the network and socket state management. --- core/src/network/network_socket.cpp | 4 ++-- core/src/server.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/network/network_socket.cpp b/core/src/network/network_socket.cpp index 71c85c8..e19391c 100644 --- a/core/src/network/network_socket.cpp +++ b/core/src/network/network_socket.cpp @@ -59,10 +59,10 @@ QHostAddress NetworkSocket::peerAddress() void NetworkSocket::close() { if (m_socket_type == TCP) { - m_client_socket.tcp->close(); + m_client_socket.tcp->deleteLater(); } else { - m_client_socket.ws->close(); + m_client_socket.ws->deleteLater(); } } diff --git a/core/src/server.cpp b/core/src/server.cpp index f8e7d02..c736a95 100644 --- a/core/src/server.cpp +++ b/core/src/server.cpp @@ -171,7 +171,9 @@ void Server::clientConnected() } int user_id = m_available_ids.pop(); - NetworkSocket *l_socket = new NetworkSocket(socket, this); + // The parent hierachry looks like this : + // QTcpSocket -> NetworkSocket -> AOClient + NetworkSocket *l_socket = new NetworkSocket(socket, socket); AOClient *client = new AOClient(this, l_socket, l_socket, user_id, music_manager); m_clients_ids.insert(user_id, client); @@ -241,7 +243,7 @@ void Server::clientConnected() void Server::ws_clientConnected() { QWebSocket *socket = ws_server->nextPendingConnection(); - NetworkSocket *l_socket = new NetworkSocket(socket, this); + NetworkSocket *l_socket = new NetworkSocket(socket, socket); // Too many players. Reject connection! // This also enforces the maximum playercount.