diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-07-26 18:53:40 +0300 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2023-10-07 21:07:06 +0300 |
commit | 6ecf43120f48adffa21f138ca1b528217f40d8cc (patch) | |
tree | 3c0e665687acf8ab71c17eeb5ec5c8504f260aef | |
parent | 738a5ad4f22d000142123b79d4bef560310012d6 (diff) |
QHttpSocketEngine: de-duplicate some code
Change-Id: I4699e3ea0d4687a9772f6f90e6033f5582c1a346
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/network/socket/qhttpsocketengine.cpp | 25 | ||||
-rw-r--r-- | 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; |