diff --git a/src/websockets/doc/snippets/src_websockets_ssl_qwebsocket.cpp b/src/websockets/doc/snippets/src_websockets_ssl_qwebsocket.cpp index 9ce9ef090867d3b564c2b5f1a2361e769175676b..78874a32991aea0aa2f137fdba360eccb3272b63 100644 --- a/src/websockets/doc/snippets/src_websockets_ssl_qwebsocket.cpp +++ b/src/websockets/doc/snippets/src_websockets_ssl_qwebsocket.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2013 Kurt Pattyn <pattyn.kurt@gmail.com> -** Contact: http://www.qt.io/licensing/ +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. ** @@ -11,8 +11,8 @@ ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Free Documentation License Usage ** Alternatively, this file may be used under the terms of the GNU Free @@ -20,7 +20,7 @@ ** Foundation and appearing in the file included in the packaging of ** this file. Please review the following information to ensure ** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/websockets/doc/src/external-resources.qdoc b/src/websockets/doc/src/external-resources.qdoc index 933ef7f90e444f3eb462d94860ece93b4e16f716..40e42573bd15f4f62a29f8d8dba4d3ca97316c3d 100644 --- a/src/websockets/doc/src/external-resources.qdoc +++ b/src/websockets/doc/src/external-resources.qdoc @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. ** @@ -11,8 +11,8 @@ ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Free Documentation License Usage ** Alternatively, this file may be used under the terms of the GNU Free @@ -20,7 +20,7 @@ ** Foundation and appearing in the file included in the packaging of ** this file. Please review the following information to ensure ** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/websockets/doc/src/index.qdoc b/src/websockets/doc/src/index.qdoc index 4f25589b5aa76e9b34b61649a5c403b5834be141..919e2fcad44d4b2b5033a8acea0c3bdd602ecd12 100644 --- a/src/websockets/doc/src/index.qdoc +++ b/src/websockets/doc/src/index.qdoc @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2013 Kurt Pattyn <pattyn.kurt@gmail.com> -** Contact: http://www.qt.io/licensing/ +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. ** @@ -11,8 +11,8 @@ ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Free Documentation License Usage ** Alternatively, this file may be used under the terms of the GNU Free @@ -20,7 +20,7 @@ ** Foundation and appearing in the file included in the packaging of ** this file. Please review the following information to ensure ** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/websockets/doc/src/overview.qdoc b/src/websockets/doc/src/overview.qdoc index e85461ac5f98955e5af58e6f580f5883ea071508..48a790f8ae101e9941086e9a3b42f3af1417dd8a 100644 --- a/src/websockets/doc/src/overview.qdoc +++ b/src/websockets/doc/src/overview.qdoc @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. ** @@ -11,8 +11,8 @@ ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Free Documentation License Usage ** Alternatively, this file may be used under the terms of the GNU Free @@ -20,7 +20,7 @@ ** Foundation and appearing in the file included in the packaging of ** this file. Please review the following information to ensure ** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/websockets/doc/src/qtwebsockets-module.qdoc b/src/websockets/doc/src/qtwebsockets-module.qdoc index 971e22c3a3cb3adad3d62be3f50b33fab0db461c..c1f7958a15e54d9a8ca1ca23b69f0864784c1eb6 100644 --- a/src/websockets/doc/src/qtwebsockets-module.qdoc +++ b/src/websockets/doc/src/qtwebsockets-module.qdoc @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2013 Kurt Pattyn <pattyn.kurt@gmail.com> -** Contact: http://www.qt.io/licensing/ +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. ** @@ -11,8 +11,8 @@ ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Free Documentation License Usage ** Alternatively, this file may be used under the terms of the GNU Free @@ -20,7 +20,7 @@ ** Foundation and appearing in the file included in the packaging of ** this file. Please review the following information to ensure ** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/websockets/qwebsocket_p.cpp b/src/websockets/qwebsocket_p.cpp index 6abffdca8c7952b1c949385b665cdc3b156233d7..1d23c84f93dfd9fa109061d5fba632f0b9cafe03 100644 --- a/src/websockets/qwebsocket_p.cpp +++ b/src/websockets/qwebsocket_p.cpp @@ -596,6 +596,9 @@ void QWebSocketPrivate::makeConnections(const QTcpSocket *pTcpSocket) QObject::connect(sslSocket, &QSslSocket::encryptedBytesWritten, q, &QWebSocket::bytesWritten); typedef void (QSslSocket:: *sslErrorSignalType)(const QList<QSslError> &); + QObjectPrivate::connect(sslSocket, + static_cast<sslErrorSignalType>(&QSslSocket::sslErrors), + this, &QWebSocketPrivate::_q_updateSslConfiguration); QObject::connect(sslSocket, static_cast<sslErrorSignalType>(&QSslSocket::sslErrors), q, &QWebSocket::sslErrors); diff --git a/src/websockets/qwebsocketserver_p.cpp b/src/websockets/qwebsocketserver_p.cpp index b7972b087ddfcae9cf7aad0fe3bcb8077357c89f..55e9484ad9a8087799f61e3fd9a8136537cfb372 100644 --- a/src/websockets/qwebsocketserver_p.cpp +++ b/src/websockets/qwebsocketserver_p.cpp @@ -490,6 +490,11 @@ void QWebSocketServerPrivate::handleConnection(QTcpSocket *pTcpSocket) const QObjectPrivate::connect(pTcpSocket, &QTcpSocket::readyRead, this, &QWebSocketServerPrivate::handshakeReceived, Qt::QueuedConnection); + if (pTcpSocket->canReadLine()) { + // We received some data! We must emit now to be sure that handshakeReceived is called + // since the data could have been received before the signal and slot was connected. + emit pTcpSocket->readyRead(); + } QObjectPrivate::connect(pTcpSocket, &QTcpSocket::disconnected, this, &QWebSocketServerPrivate::onSocketDisconnected); } diff --git a/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp b/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp index 8f3e29306a9ba1f13cae247f528f835c45401db0..8a3760d851b7c1da039b145e5ea661443f84e826 100644 --- a/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp +++ b/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp @@ -31,9 +31,9 @@ #include <QTcpServer> #ifndef QT_NO_OPENSSL #include <QtNetwork/qsslpresharedkeyauthenticator.h> -#include <QtNetwork/qsslcipher.h> #endif #ifndef QT_NO_SSL +#include <QtNetwork/qsslcipher.h> #include <QtNetwork/qsslkey.h> #endif #include <QtWebSockets/QWebSocketServer> @@ -301,7 +301,7 @@ void tst_QWebSocketServer::tst_listening() QVERIFY(server.isListening()); QCOMPARE(serverClosedSpy.count(), 0); server.close(); - QVERIFY(serverClosedSpy.wait(1000)); + QTRY_COMPARE(serverClosedSpy.count(), 1); QVERIFY(!server.isListening()); QCOMPARE(serverErrorSpy.count(), 0); @@ -347,8 +347,7 @@ void tst_QWebSocketServer::tst_connectivity() socket.open(server.serverUrl().toString()); - if (socketConnectedSpy.count() == 0) - QVERIFY(socketConnectedSpy.wait()); + QTRY_COMPARE(socketConnectedSpy.count(), 1); QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); QCOMPARE(serverConnectionSpy.count(), 1); QCOMPARE(corsAuthenticationSpy.count(), 1); @@ -357,8 +356,7 @@ void tst_QWebSocketServer::tst_connectivity() server.close(); - QVERIFY(serverClosedSpy.wait()); - QCOMPARE(serverClosedSpy.count(), 1); + QTRY_COMPARE(serverClosedSpy.count(), 1); #ifndef QT_NO_SSL QCOMPARE(peerVerifyErrorSpy.count(), 0); QCOMPARE(sslErrorsSpy.count(), 0); @@ -429,8 +427,7 @@ void tst_QWebSocketServer::tst_preSharedKey() socket.open(server.serverUrl().toString()); - if (socketConnectedSpy.count() == 0) - QVERIFY(socketConnectedSpy.wait()); + QTRY_COMPARE(socketConnectedSpy.count(), 1); QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); QCOMPARE(serverConnectionSpy.count(), 1); QCOMPARE(serverPskRequiredSpy.count(), 1); @@ -440,8 +437,7 @@ void tst_QWebSocketServer::tst_preSharedKey() server.close(); - QVERIFY(serverClosedSpy.wait()); - QCOMPARE(serverClosedSpy.count(), 1); + QTRY_COMPARE(serverClosedSpy.count(), 1); QCOMPARE(sslErrorsSpy.count(), 0); QCOMPARE(serverErrorSpy.count(), 0); #endif @@ -480,20 +476,18 @@ void tst_QWebSocketServer::tst_maxPendingConnections() socket1.open(server.serverUrl().toString()); - if (socket1ConnectedSpy.count() == 0) - QVERIFY(socket1ConnectedSpy.wait()); + QTRY_COMPARE(socket1ConnectedSpy.count(), 1); QCOMPARE(socket1.state(), QAbstractSocket::ConnectedState); QCOMPARE(serverConnectionSpy.count(), 1); QCOMPARE(corsAuthenticationSpy.count(), 1); socket2.open(server.serverUrl().toString()); - if (socket2ConnectedSpy.count() == 0) - QVERIFY(socket2ConnectedSpy.wait()); + QTRY_COMPARE(socket2ConnectedSpy.count(), 1); QCOMPARE(socket2.state(), QAbstractSocket::ConnectedState); QCOMPARE(serverConnectionSpy.count(), 2); QCOMPARE(corsAuthenticationSpy.count(), 2); socket3.open(server.serverUrl().toString()); - if (socket3ConnectedSpy.count() == 0) - QVERIFY(!socket3ConnectedSpy.wait(250)); + QVERIFY(!socket3ConnectedSpy.wait(250)); + QCOMPARE(socket3ConnectedSpy.count(), 0); QCOMPARE(socket3.state(), QAbstractSocket::UnconnectedState); QCOMPARE(serverConnectionSpy.count(), 2); QCOMPARE(corsAuthenticationSpy.count(), 2); @@ -519,8 +513,7 @@ void tst_QWebSocketServer::tst_maxPendingConnections() server.close(); - QVERIFY(serverClosedSpy.wait()); - QCOMPARE(serverClosedSpy.count(), 1); + QTRY_COMPARE(serverClosedSpy.count(), 1); #ifndef QT_NO_SSL QCOMPARE(peerVerifyErrorSpy.count(), 0); QCOMPARE(sslErrorsSpy.count(), 0); @@ -550,8 +543,7 @@ void tst_QWebSocketServer::tst_serverDestroyedWhileSocketConnected() socket.open(server->serverUrl().toString()); - if (socketConnectedSpy.count() == 0) - QVERIFY(socketConnectedSpy.wait()); + QTRY_COMPARE(socketConnectedSpy.count(), 1); QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); QCOMPARE(serverConnectionSpy.count(), 1); QCOMPARE(corsAuthenticationSpy.count(), 1); @@ -560,9 +552,7 @@ void tst_QWebSocketServer::tst_serverDestroyedWhileSocketConnected() delete server; - if (socketDisconnectedSpy.count() == 0) - QVERIFY(socketDisconnectedSpy.wait()); - QCOMPARE(socketDisconnectedSpy.count(), 1); + QTRY_COMPARE(socketDisconnectedSpy.count(), 1); } void tst_QWebSocketServer::tst_scheme() @@ -578,8 +568,7 @@ void tst_QWebSocketServer::tst_scheme() QWebSocket plainSocket; plainSocket.open(plainServer.serverUrl().toString()); - if (plainServerConnectionSpy.count() == 0) - QVERIFY(plainServerConnectionSpy.wait()); + QTRY_COMPARE(plainServerConnectionSpy.count(), 1); QScopedPointer<QWebSocket> plainServerSocket(plainServer.nextPendingConnection()); QVERIFY(!plainServerSocket.isNull()); QCOMPARE(plainServerSocket->requestUrl().scheme(), QStringLiteral("ws")); @@ -605,18 +594,21 @@ void tst_QWebSocketServer::tst_scheme() QVERIFY(secureServer.listen()); + QSslCipher sessionCipher; QWebSocket secureSocket; - typedef void (QWebSocket::* ignoreSslErrorsSlot)(); connect(&secureSocket, &QWebSocket::sslErrors, - &secureSocket, static_cast<ignoreSslErrorsSlot>(&QWebSocket::ignoreSslErrors)); + &secureSocket, [&] { + secureSocket.ignoreSslErrors(); + sessionCipher = secureSocket.sslConfiguration().sessionCipher(); + }); secureSocket.open(secureServer.serverUrl().toString()); - if (secureServerConnectionSpy.count() == 0) - QVERIFY(secureServerConnectionSpy.wait()); + QTRY_COMPARE(secureServerConnectionSpy.count(), 1); QScopedPointer<QWebSocket> secureServerSocket(secureServer.nextPendingConnection()); QVERIFY(!secureServerSocket.isNull()); QCOMPARE(secureServerSocket->requestUrl().scheme(), QStringLiteral("wss")); secureServer.close(); + QVERIFY(!sessionCipher.isNull()); #endif } @@ -635,19 +627,17 @@ void tst_QWebSocketServer::tst_handleConnection() QWebSocket webSocket; QSignalSpy wsConnectedSpy(&webSocket, &QWebSocket::connected); webSocket.open(QStringLiteral("ws://localhost:%1").arg(tcpServer.serverPort())); - QVERIFY(wsConnectedSpy.wait()); + QTRY_COMPARE(wsConnectedSpy.count(), 1); - if (wsServerConnectionSpy.isEmpty()) - QVERIFY(wsServerConnectionSpy.wait()); + QTRY_COMPARE(wsServerConnectionSpy.count(), 1); QScopedPointer<QWebSocket> webServerSocket(wsServer.nextPendingConnection()); QVERIFY(!webServerSocket.isNull()); QSignalSpy wsMessageReceivedSpy(webServerSocket.data(), &QWebSocket::textMessageReceived); webSocket.sendTextMessage("dummy"); - wsMessageReceivedSpy.wait(); - QCOMPARE(wsMessageReceivedSpy.count(), 1); + QTRY_COMPARE(wsMessageReceivedSpy.count(), 1); QList<QVariant> arguments = wsMessageReceivedSpy.takeFirst(); QCOMPARE(arguments.first().toString(), QString("dummy")); }