summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2019-08-26 17:05:43 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2019-08-26 15:40:58 +0000
commit6e1fa958c289de639753a60a9384bd94db0e91a8 (patch)
treee7a61fb0d86d5e5ae8b3533f37e2cf999b0cdf54
parent746e15b32b91dd662ba18302c9e029dc2dace645 (diff)
downloadqtwebsockets-6e1fa958c289de639753a60a9384bd94db0e91a8.tar.gz
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 <edward.welbourne@qt.io>
-rw-r--r--tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp28
1 files changed, 28 insertions, 0 deletions
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<QWebSocket>(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"