From 30b5e99da347aea446a5a3a334a21a4406adc4fe Mon Sep 17 00:00:00 2001
From: Luca Niccoli <lultimouomo@gmail.com>
Date: Mon, 9 Mar 2015 19:20:26 +0100
Subject: [PATCH] Always initialize m_handshakeState

The client-side constructor was leaving it uninitialized, which would
sometimes lead to spurious error signals being emitted.

Task-number: QTBUG-44893
Change-Id: I7a17f1a16d9a5fe4218beb6d92993c1889ad836b
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
---
 src/websockets/qwebsocket_p.cpp          | 3 ++-
 tests/auto/qwebsocket/tst_qwebsocket.cpp | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/websockets/qwebsocket_p.cpp b/src/websockets/qwebsocket_p.cpp
index 2bb51512..8aa2fe1f 100644
--- a/src/websockets/qwebsocket_p.cpp
+++ b/src/websockets/qwebsocket_p.cpp
@@ -105,7 +105,8 @@ QWebSocketPrivate::QWebSocketPrivate(const QString &origin, QWebSocketProtocol::
     m_dataProcessor(),
     m_configuration(),
     m_pMaskGenerator(&m_defaultMaskGenerator),
-    m_defaultMaskGenerator()
+    m_defaultMaskGenerator(),
+    m_handshakeState(NothingDoneState)
 {
 }
 
diff --git a/tests/auto/qwebsocket/tst_qwebsocket.cpp b/tests/auto/qwebsocket/tst_qwebsocket.cpp
index 900f3161..7659e898 100644
--- a/tests/auto/qwebsocket/tst_qwebsocket.cpp
+++ b/tests/auto/qwebsocket/tst_qwebsocket.cpp
@@ -410,6 +410,7 @@ void tst_QWebSocket::tst_sendTextMessage()
     QSignalSpy textFrameReceived(&socket, SIGNAL(textFrameReceived(QString,bool)));
     QSignalSpy binaryMessageReceived(&socket, SIGNAL(binaryMessageReceived(QByteArray)));
     QSignalSpy binaryFrameReceived(&socket, SIGNAL(binaryFrameReceived(QByteArray,bool)));
+    QSignalSpy socketError(&socket, SIGNAL(error(QAbstractSocket::SocketError)));
 
     QUrl url = QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() +
                     QStringLiteral(":") + QString::number(echoServer.port()));
@@ -419,6 +420,7 @@ void tst_QWebSocket::tst_sendTextMessage()
 
     if (socketConnectedSpy.count() == 0)
         QVERIFY(socketConnectedSpy.wait(500));
+    QCOMPARE(socketError.count(), 0);
     QCOMPARE(socket.state(), QAbstractSocket::ConnectedState);
 
     socket.sendTextMessage(QStringLiteral("Hello world!"));
-- 
GitLab