From 6ecf43120f48adffa21f138ca1b528217f40d8cc Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Wed, 26 Jul 2023 18:53:40 +0300 Subject: [PATCH] QHttpSocketEngine: de-duplicate some code Change-Id: I4699e3ea0d4687a9772f6f90e6033f5582c1a346 Reviewed-by: Thiago Macieira --- src/network/socket/qhttpsocketengine.cpp | 25 +++++++++++++----------- src/network/socket/qhttpsocketengine_p.h | 2 ++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/network/socket/qhttpsocketengine.cpp b/src/network/socket/qhttpsocketengine.cpp index 07d24dd91b..c339912240 100644 --- a/src/network/socket/qhttpsocketengine.cpp +++ b/src/network/socket/qhttpsocketengine.cpp @@ -329,11 +329,7 @@ bool QHttpSocketEngine::waitForRead(QDeadlineTimer deadline, bool *timedOut) } } - // If we're not connected yet, wait until we are, or until an error - // occurs. - while (d->state != Connected && d->socket->waitForReadyRead(deadline.remainingTime())) { - // Loop while the protocol handshake is taking place. - } + waitForProtocolHandshake(deadline); // Report any error that may occur. if (d->state != Connected) { @@ -361,12 +357,7 @@ bool QHttpSocketEngine::waitForWrite(QDeadlineTimer deadline, bool *timedOut) return true; } - // If we're not connected yet, wait until we are, and until bytes have - // been received (i.e., the socket has connected, we have sent the - // greeting, and then received the response). - while (d->state != Connected && d->socket->waitForReadyRead(deadline.remainingTime())) { - // Loop while the protocol handshake is taking place. - } + waitForProtocolHandshake(deadline); // Report any error that may occur. if (d->state != Connected) { @@ -399,6 +390,18 @@ bool QHttpSocketEngine::waitForReadOrWrite(bool *readyToRead, bool *readyToWrite return canWrite; } +void QHttpSocketEngine::waitForProtocolHandshake(QDeadlineTimer deadline) const +{ + Q_D(const QHttpSocketEngine); + + // If we're not connected yet, wait until we are (and until bytes have + // been received, i.e. the socket has connected, we have sent the + // greeting, and then received the response), or until an error occurs. + while (d->state != Connected && d->socket->waitForReadyRead(deadline.remainingTime())) { + // Loop while the protocol handshake is taking place. + } +} + bool QHttpSocketEngine::isReadNotificationEnabled() const { Q_D(const QHttpSocketEngine); diff --git a/src/network/socket/qhttpsocketengine_p.h b/src/network/socket/qhttpsocketengine_p.h index 70ffd06b6b..7926abf513 100644 --- a/src/network/socket/qhttpsocketengine_p.h +++ b/src/network/socket/qhttpsocketengine_p.h @@ -101,6 +101,8 @@ public: QDeadlineTimer deadline = QDeadlineTimer{DefaultTimeout}, bool *timedOut = nullptr) override; + void waitForProtocolHandshake(QDeadlineTimer deadline) const; + bool isReadNotificationEnabled() const override; void setReadNotificationEnabled(bool enable) override; bool isWriteNotificationEnabled() const override;