summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2014-12-02 13:15:54 +0100
committerFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2014-12-29 16:49:54 +0100
commit5f8093e6f985a7a887ffaa1e2fecd7314b5444c6 (patch)
tree20fe90121185373d1f561dcc04a61c6bd6766f8e
parentdf320becb3d23ea99bf1ddfc190557e7a1729928 (diff)
downloadqtwebsockets-5.4.1.tar.gz
QWebSocket should remember close code and reasonv5.4.15.4.1
Task-number: QTBUG-42982 Change-Id: I50dbff96d7d64a5213e6ea6ba7bb9429b21b1fb2 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
-rw-r--r--src/websockets/qwebsocket_p.cpp2
-rw-r--r--tests/auto/qwebsocket/tst_qwebsocket.cpp5
2 files changed, 7 insertions, 0 deletions
diff --git a/src/websockets/qwebsocket_p.cpp b/src/websockets/qwebsocket_p.cpp
index f483e12..45913e5 100644
--- a/src/websockets/qwebsocket_p.cpp
+++ b/src/websockets/qwebsocket_p.cpp
@@ -300,6 +300,8 @@ void QWebSocketPrivate::close(QWebSocketProtocol::CloseCode closeCode, QString r
return;
if (!m_isClosingHandshakeSent) {
Q_Q(QWebSocket);
+ m_closeCode = closeCode;
+ m_closeReason = reason;
const quint16 code = qToBigEndian<quint16>(closeCode);
QByteArray payload;
payload.append(static_cast<const char *>(static_cast<const void *>(&code)), 2);
diff --git a/tests/auto/qwebsocket/tst_qwebsocket.cpp b/tests/auto/qwebsocket/tst_qwebsocket.cpp
index 0d1a46d..0e04ce1 100644
--- a/tests/auto/qwebsocket/tst_qwebsocket.cpp
+++ b/tests/auto/qwebsocket/tst_qwebsocket.cpp
@@ -471,6 +471,11 @@ void tst_QWebSocket::tst_sendTextMessage()
isLastFrame = arguments.at(1).toBool();
QCOMPARE(frameReceived, QStringLiteral("Hello world!"));
QVERIFY(isLastFrame);
+
+ QString reason = QStringLiteral("going away");
+ socket.close(QWebSocketProtocol::CloseCodeGoingAway, reason);
+ QCOMPARE(socket.closeCode(), QWebSocketProtocol::CloseCodeGoingAway);
+ QCOMPARE(socket.closeReason(), reason);
#endif
}