summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-11-25 20:41:39 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-11-26 17:35:39 +0100
commit92cec7af3ee88673d58e70e5b9a84a0cf55aa734 (patch)
tree76188f325774337655dab3400c37bef44e4f646e
parentb45ebeece5ee63a94b4ac3c10347e2e14e1fa311 (diff)
downloadqtwebsockets-92cec7af3ee88673d58e70e5b9a84a0cf55aa734.tar.gz
Cleanup QWebSocketFrame
Remove QWebSocketFrame assignment and move stuff by our own - the default ones are good. Also reorder the members to reduce the padding (56 to 48 bytes on 64bits). Change-Id: Ib4628628af924c36ad3cd9bf67ce72752ef97ff5 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
-rw-r--r--src/websockets/qwebsocketframe.cpp122
-rw-r--r--src/websockets/qwebsocketframe_p.h40
-rw-r--r--tests/auto/websockets/websocketframe/tst_websocketframe.cpp26
3 files changed, 26 insertions, 162 deletions
diff --git a/src/websockets/qwebsocketframe.cpp b/src/websockets/qwebsocketframe.cpp
index 11373a7..cfa63ed 100644
--- a/src/websockets/qwebsocketframe.cpp
+++ b/src/websockets/qwebsocketframe.cpp
@@ -64,128 +64,6 @@ QT_BEGIN_NAMESPACE
/*!
\internal
*/
-QWebSocketFrame::QWebSocketFrame() :
- m_closeCode(QWebSocketProtocol::CloseCodeNormal),
- m_closeReason(),
- m_mask(0),
- m_opCode(QWebSocketProtocol::OpCodeReservedC),
- m_length(0),
- m_payload(),
- m_isFinalFrame(true),
- m_rsv1(false),
- m_rsv2(false),
- m_rsv3(false),
- m_isValid(false)
-{
-}
-
-/*!
- \internal
- */
-QWebSocketFrame::QWebSocketFrame(const QWebSocketFrame &other) :
- m_closeCode(other.m_closeCode),
- m_closeReason(other.m_closeReason),
- m_mask(other.m_mask),
- m_opCode(other.m_opCode),
- m_length(other.m_length),
- m_payload(other.m_payload),
- m_isFinalFrame(other.m_isFinalFrame),
- m_rsv1(other.m_rsv1),
- m_rsv2(other.m_rsv2),
- m_rsv3(other.m_rsv3),
- m_isValid(other.m_isValid),
- m_processingState(other.m_processingState)
-{
-}
-
-/*!
- \internal
- */
-QWebSocketFrame &QWebSocketFrame::operator =(const QWebSocketFrame &other)
-{
- m_closeCode = other.m_closeCode;
- m_closeReason = other.m_closeReason;
- m_isFinalFrame = other.m_isFinalFrame;
- m_mask = other.m_mask;
- m_rsv1 = other.m_rsv1;
- m_rsv2 = other.m_rsv2;
- m_rsv3 = other.m_rsv3;
- m_opCode = other.m_opCode;
- m_length = other.m_length;
- m_payload = other.m_payload;
- m_isValid = other.m_isValid;
- m_processingState = other.m_processingState;
-
- return *this;
-}
-
-#ifdef Q_COMPILER_RVALUE_REFS
-/*!
- \internal
- */
-QWebSocketFrame::QWebSocketFrame(QWebSocketFrame &&other) :
- m_closeCode(qMove(other.m_closeCode)),
- m_closeReason(qMove(other.m_closeReason)),
- m_mask(qMove(other.m_mask)),
- m_opCode(qMove(other.m_opCode)),
- m_length(qMove(other.m_length)),
- m_payload(qMove(other.m_payload)),
- m_isFinalFrame(qMove(other.m_isFinalFrame)),
- m_rsv1(qMove(other.m_rsv1)),
- m_rsv2(qMove(other.m_rsv2)),
- m_rsv3(qMove(other.m_rsv3)),
- m_isValid(qMove(other.m_isValid)),
- m_processingState(qMove(other.m_processingState))
-{}
-
-
-/*!
- \internal
- */
-QWebSocketFrame &QWebSocketFrame::operator =(QWebSocketFrame &&other)
-{
- qSwap(m_closeCode, other.m_closeCode);
- qSwap(m_closeReason, other.m_closeReason);
- qSwap(m_isFinalFrame, other.m_isFinalFrame);
- qSwap(m_mask, other.m_mask);
- qSwap(m_rsv1, other.m_rsv1);
- qSwap(m_rsv2, other.m_rsv2);
- qSwap(m_rsv3, other.m_rsv3);
- qSwap(m_opCode, other.m_opCode);
- qSwap(m_length, other.m_length);
- qSwap(m_payload, other.m_payload);
- qSwap(m_isValid, other.m_isValid);
- qSwap(m_processingState, other.m_processingState);
-
- return *this;
-}
-
-#endif
-
-/*!
- \internal
- */
-void QWebSocketFrame::swap(QWebSocketFrame &other)
-{
- if (&other != this) {
- qSwap(m_closeCode, other.m_closeCode);
- qSwap(m_closeReason, other.m_closeReason);
- qSwap(m_isFinalFrame, other.m_isFinalFrame);
- qSwap(m_mask, other.m_mask);
- qSwap(m_rsv1, other.m_rsv1);
- qSwap(m_rsv2, other.m_rsv2);
- qSwap(m_rsv3, other.m_rsv3);
- qSwap(m_opCode, other.m_opCode);
- qSwap(m_length, other.m_length);
- qSwap(m_payload, other.m_payload);
- qSwap(m_isValid, other.m_isValid);
- qSwap(m_processingState, other.m_processingState);
- }
-}
-
-/*!
- \internal
- */
QWebSocketProtocol::CloseCode QWebSocketFrame::closeCode() const
{
return isDone() ? m_closeCode : QWebSocketProtocol::CloseCodeGoingAway;
diff --git a/src/websockets/qwebsocketframe_p.h b/src/websockets/qwebsocketframe_p.h
index e2b4e9f..a8b9684 100644
--- a/src/websockets/qwebsocketframe_p.h
+++ b/src/websockets/qwebsocketframe_p.h
@@ -54,7 +54,7 @@
#include <QtCore/QString>
#include <QtCore/QByteArray>
#include <QtCore/QCoreApplication>
-#include <limits.h>
+#include <limits>
#include "qwebsockets_global.h"
#include "qwebsocketprotocol.h"
@@ -64,25 +64,15 @@ QT_BEGIN_NAMESPACE
class QIODevice;
-const quint64 MAX_FRAME_SIZE_IN_BYTES = INT_MAX - 1;
-const quint64 MAX_MESSAGE_SIZE_IN_BYTES = INT_MAX - 1;
+const quint64 MAX_FRAME_SIZE_IN_BYTES = std::numeric_limits<int>::max() - 1;
+const quint64 MAX_MESSAGE_SIZE_IN_BYTES = std::numeric_limits<int>::max() - 1;
class Q_AUTOTEST_EXPORT QWebSocketFrame
{
Q_DECLARE_TR_FUNCTIONS(QWebSocketFrame)
public:
- QWebSocketFrame();
- QWebSocketFrame(const QWebSocketFrame &other);
-
- QWebSocketFrame &operator =(const QWebSocketFrame &other);
-
-#ifdef Q_COMPILER_RVALUE_REFS
- QWebSocketFrame(QWebSocketFrame &&other);
- QWebSocketFrame &operator =(QWebSocketFrame &&other);
-#endif
-
- void swap(QWebSocketFrame &other);
+ QWebSocketFrame() = default;
QWebSocketProtocol::CloseCode closeCode() const;
QString closeReason() const;
@@ -106,18 +96,12 @@ public:
void readFrame(QIODevice *pIoDevice);
private:
- QWebSocketProtocol::CloseCode m_closeCode;
QString m_closeReason;
- quint32 m_mask;
- QWebSocketProtocol::OpCode m_opCode;
- quint64 m_length;
QByteArray m_payload;
-
- bool m_isFinalFrame;
- bool m_rsv1;
- bool m_rsv2;
- bool m_rsv3;
- bool m_isValid;
+ quint64 m_length = 0;
+ quint32 m_mask = 0;
+ QWebSocketProtocol::CloseCode m_closeCode = QWebSocketProtocol::CloseCodeNormal;
+ QWebSocketProtocol::OpCode m_opCode = QWebSocketProtocol::OpCodeReservedC;
enum ProcessingState
{
@@ -127,7 +111,13 @@ private:
PS_READ_PAYLOAD,
PS_DISPATCH_RESULT,
PS_WAIT_FOR_MORE_DATA
- } m_processingState{PS_READ_HEADER};
+ } m_processingState = PS_READ_HEADER;
+
+ bool m_isFinalFrame = true;
+ bool m_rsv1 = false;
+ bool m_rsv2 = false;
+ bool m_rsv3 = false;
+ bool m_isValid = false;
ProcessingState readFrameHeader(QIODevice *pIoDevice);
ProcessingState readFramePayloadLength(QIODevice *pIoDevice);
diff --git a/tests/auto/websockets/websocketframe/tst_websocketframe.cpp b/tests/auto/websockets/websocketframe/tst_websocketframe.cpp
index 6b9aaaf..bbf0e5f 100644
--- a/tests/auto/websockets/websocketframe/tst_websocketframe.cpp
+++ b/tests/auto/websockets/websocketframe/tst_websocketframe.cpp
@@ -201,8 +201,8 @@ void tst_WebSocketFrame::tst_copyConstructorAndAssignment()
frame.readFrame(&buffer);
buffer.close();
+ auto compareFrames = [](const QWebSocketFrame &other, const QWebSocketFrame &frame)
{
- QWebSocketFrame other(frame);
QCOMPARE(other.closeCode(), frame.closeCode());
QCOMPARE(other.closeReason(), frame.closeReason());
QCOMPARE(other.hasMask(), frame.hasMask());
@@ -217,24 +217,20 @@ void tst_WebSocketFrame::tst_copyConstructorAndAssignment()
QCOMPARE(other.rsv1(), frame.rsv1());
QCOMPARE(other.rsv2(), frame.rsv2());
QCOMPARE(other.rsv3(), frame.rsv3());
+ };
+
+ {
+ QWebSocketFrame other(frame);
+ compareFrames(other, frame);
}
{
QWebSocketFrame other;
other = frame;
- QCOMPARE(other.closeCode(), frame.closeCode());
- QCOMPARE(other.closeReason(), frame.closeReason());
- QCOMPARE(other.hasMask(), frame.hasMask());
- QCOMPARE(other.isContinuationFrame(), frame.isContinuationFrame());
- QCOMPARE(other.isControlFrame(), frame.isControlFrame());
- QCOMPARE(other.isDataFrame(), frame.isDataFrame());
- QCOMPARE(other.isFinalFrame(), frame.isFinalFrame());
- QCOMPARE(other.isValid(), frame.isValid());
- QCOMPARE(other.mask(), frame.mask());
- QCOMPARE(other.opCode(), frame.opCode());
- QCOMPARE(other.payload(), frame.payload());
- QCOMPARE(other.rsv1(), frame.rsv1());
- QCOMPARE(other.rsv2(), frame.rsv2());
- QCOMPARE(other.rsv3(), frame.rsv3());
+ compareFrames(other, frame);
+ QWebSocketFrame other2 = std::move(other);
+ compareFrames(other2, frame);
+ QWebSocketFrame other3(std::move(other2));
+ compareFrames(other3, frame);
}
}