diff options
Diffstat (limited to 'src/websockets/qwebsocketdataprocessor.cpp')
-rw-r--r-- | src/websockets/qwebsocketdataprocessor.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/websockets/qwebsocketdataprocessor.cpp b/src/websockets/qwebsocketdataprocessor.cpp index 4f81222..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); } /*! @@ -125,8 +129,14 @@ void QWebSocketDataProcessor::process(QIODevice *pIoDevice) bool isDone = false; while (!isDone) { - QWebSocketFrame frame = QWebSocketFrame::readFrame(pIoDevice); - if (Q_LIKELY(frame.isValid())) { + frame.readFrame(pIoDevice); + 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 { @@ -199,6 +209,7 @@ void QWebSocketDataProcessor::process(QIODevice *pIoDevice) clear(); isDone = true; } + frame.clear(); } } @@ -301,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 |