diff options
author | Ryan Chu <ryan.chu@qt.io> | 2019-06-28 14:37:05 +0200 |
---|---|---|
committer | Ryan Chu <ryan.chu@qt.io> | 2019-08-23 15:28:46 +0200 |
commit | b14f5f59a3ae96949e6a33302385a751d6448182 (patch) | |
tree | 5594f3816864eaf6757bcadeecebb84a67b8c2e7 /src/websockets/qwebsocketdataprocessor.cpp | |
parent | 24894c032719157a2d738f03e0c70d3ff0cf1782 (diff) | |
download | qtwebsockets-b14f5f59a3ae96949e6a33302385a751d6448182.tar.gz |
Remove waitForReadyRead from QWebSocketFrame::readFrame
Asynchronously process socket frame in QWebSocketDataProcessor::process.
If the processing of QWebSocketFrame is not done and waiting for more
data, QWebSocketDataProcessor::process will return the control and wait
for next readyRead signal to continue processing the unfinished socket
frame. QWebSocketDataProcessor::process gets timeout after 5 seconds,
and then an errorEncountered signal will be emitted.
Fixes: QTBUG-74464
Change-Id: I03b7f874c1c266617e7eadf59c59ae43fa8540ce
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/websockets/qwebsocketdataprocessor.cpp')
-rw-r--r-- | src/websockets/qwebsocketdataprocessor.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/websockets/qwebsocketdataprocessor.cpp b/src/websockets/qwebsocketdataprocessor.cpp index ee28969..39287d4 100644 --- a/src/websockets/qwebsocketdataprocessor.cpp +++ b/src/websockets/qwebsocketdataprocessor.cpp @@ -87,6 +87,10 @@ QWebSocketDataProcessor::QWebSocketDataProcessor(QObject *parent) : m_pTextCodec(QTextCodec::codecForName("UTF-8")) { clear(); + // initialize the internal timeout timer + waitTimer.setInterval(5000); + waitTimer.setSingleShot(true); + waitTimer.callOnTimeout(this, &QWebSocketDataProcessor::timeout); } /*! @@ -126,7 +130,13 @@ void QWebSocketDataProcessor::process(QIODevice *pIoDevice) while (!isDone) { frame.readFrame(pIoDevice); - if (Q_LIKELY(frame.isValid())) { + if (!frame.isDone()) { + // waiting for more data available + QObject::connect(pIoDevice, &QIODevice::readyRead, + &waitTimer, &QTimer::stop, Qt::UniqueConnection); + waitTimer.start(); + return; + } else if (Q_LIKELY(frame.isValid())) { if (frame.isControlFrame()) { isDone = processControlFrame(frame); } else { @@ -302,4 +312,14 @@ bool QWebSocketDataProcessor::processControlFrame(const QWebSocketFrame &frame) return mustStopProcessing; } +/*! + \internal + */ +void QWebSocketDataProcessor::timeout() +{ + clear(); + Q_EMIT errorEncountered(QWebSocketProtocol::CloseCodeGoingAway, + tr("Timeout when reading data from socket.")); +} + QT_END_NAMESPACE |