From df5a240189177fbc05478cb8a7765068927c3d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Tue, 4 Jun 2019 22:26:52 +0200 Subject: [PATCH] Add flush and abort to each socket close call --- libnymea-remoteproxy/websocketserver.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libnymea-remoteproxy/websocketserver.cpp b/libnymea-remoteproxy/websocketserver.cpp index 7e49836..9e60d94 100644 --- a/libnymea-remoteproxy/websocketserver.cpp +++ b/libnymea-remoteproxy/websocketserver.cpp @@ -87,6 +87,8 @@ void WebSocketServer::killClientConnection(const QUuid &clientId, const QString qCWarning(dcWebSocketServer()) << "Killing client connection" << clientId.toString() << "Reason:" << killReason; client->close(QWebSocketProtocol::CloseCodeBadOperation, killReason); + client->flush(); + client->abort(); } void WebSocketServer::onClientConnected() @@ -102,6 +104,8 @@ void WebSocketServer::onClientConnected() if (client->version() != QWebSocketProtocol::Version13) { qCWarning(dcWebSocketServer()) << "Client with invalid protocol version" << client->version() << ". Rejecting."; client->close(QWebSocketProtocol::CloseCodeProtocolError, QString("invalid protocol version: %1 != Supported Version 13").arg(client->version())); + client->flush(); + client->abort(); delete client; return; } @@ -130,6 +134,8 @@ void WebSocketServer::onClientDisconnected() // Manually close it in any case client->close(); + client->flush(); + client->abort(); m_clientList.take(clientId)->deleteLater(); emit clientDisconnected(clientId); @@ -148,6 +154,8 @@ void WebSocketServer::onBinaryMessageReceived(const QByteArray &data) qCWarning(dcWebSocketServerTraffic()) << "<-- Binary message from" << client->peerAddress().toString() << ":" << data; // Note: this is not expected, so close this client connection. client->close(QWebSocketProtocol::CloseCodeBadOperation, "Binary message not expected."); + client->flush(); + client->abort(); } void WebSocketServer::onClientError(QAbstractSocket::SocketError error) @@ -157,6 +165,8 @@ void WebSocketServer::onClientError(QAbstractSocket::SocketError error) // Note: on any error which can occure, make sure the socket will be closed in any case client->close(); + client->flush(); + client->abort(); } void WebSocketServer::onAcceptError(QAbstractSocket::SocketError error) @@ -195,6 +205,8 @@ bool WebSocketServer::stopServer() // Clean up client connections foreach (QWebSocket *client, m_clientList.values()) { client->close(QWebSocketProtocol::CloseCodeNormal, "Stop server"); + client->flush(); + client->abort(); } // Delete the server object