From 6e1fa958c289de639753a60a9384bd94db0e91a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Mon, 26 Aug 2019 17:05:43 +0200 Subject: Properly handle multiple websocket frames in one TCP frame Since we can have multiple websocket frames in one TCP frame we need to handle them all. Partial revert of b14f5f59a3ae96949e6a33302385a751d6448182 Fixes: QTBUG-77830 Change-Id: If435f6e67f04e4817a3202eb8fe779243591bff3 Reviewed-by: Edward Welbourne --- .../qwebsocketserver/tst_qwebsocketserver.cpp | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp b/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp index 442196b..20d7060 100644 --- a/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp +++ b/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp @@ -116,6 +116,7 @@ private Q_SLOTS: void tst_scheme(); // qtbug-55927 void tst_handleConnection(); void tst_handshakeTimeout(); // qtbug-63312, qtbug-57026 + void multipleFrames(); private: bool m_shouldSkipUnsupportedIpv6Test; @@ -823,6 +824,33 @@ void tst_QWebSocketServer::tst_handshakeTimeout() } } +void tst_QWebSocketServer::multipleFrames() +{ + QWebSocketServer server(QString(), QWebSocketServer::NonSecureMode); + QSignalSpy serverConnectionSpy(&server, &QWebSocketServer::newConnection); + QVERIFY(server.listen()); + + QWebSocket socket; + QSignalSpy socketConnectedSpy(&socket, &QWebSocket::connected); + QSignalSpy messageReceivedSpy(&socket, &QWebSocket::binaryMessageReceived); + socket.open(server.serverUrl().toString()); + + QVERIFY(serverConnectionSpy.wait()); + QVERIFY(socketConnectedSpy.wait()); + + auto serverSocket = std::unique_ptr(server.nextPendingConnection()); + QVERIFY(serverSocket); + for (int i = 0; i < 10; i++) + serverSocket->sendBinaryMessage(QByteArray("abc")); + if (serverSocket->bytesToWrite()) + QVERIFY(serverSocket->flush()); + + QVERIFY(messageReceivedSpy.wait()); + // Since there's no guarantee the operating system will fit all 10 websocket frames into 1 tcp + // frame, let's just assume it will do at least 2. EXCEPT_FAIL any which doesn't merge any. + QVERIFY2(messageReceivedSpy.count() > 1, "Received only 1 message in the TCP frame!"); +} + QTEST_MAIN(tst_QWebSocketServer) #include "tst_qwebsocketserver.moc" -- cgit v1.2.1