Add flush and abort to each socket close call

This commit is contained in:
Simon Stürz 2019-06-04 22:26:52 +02:00 committed by Simon Stürz
parent bdda8da803
commit df5a240189

View File

@ -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