diff options
author | Ahmad Samir <[email protected]> | 2023-07-26 19:53:20 +0300 |
---|---|---|
committer | Ahmad Samir <[email protected]> | 2023-10-07 21:07:06 +0300 |
commit | b3586725562bf5fd616774ca9f088867a2ec8391 (patch) | |
tree | f53698ebbe4c91b4e3aa62a375b3353ddbff1f2b | |
parent | 6ecf43120f48adffa21f138ca1b528217f40d8cc (diff) |
QLocalSocket: port to QDeadlineTimer
Easier logic for such use-cases.
Change-Id: I4ce14bbaeda5441294f33993195396d9f47710dc
Reviewed-by: Thiago Macieira <[email protected]>
-rw-r--r-- | src/network/socket/qlocalsocket_unix.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/network/socket/qlocalsocket_unix.cpp b/src/network/socket/qlocalsocket_unix.cpp index 626d46d7bf4..6e9133ad8f4 100644 --- a/src/network/socket/qlocalsocket_unix.cpp +++ b/src/network/socket/qlocalsocket_unix.cpp @@ -13,14 +13,16 @@ #include <errno.h> #include <qdir.h> +#include <qdeadlinetimer.h> #include <qdebug.h> -#include <qelapsedtimer.h> #include <qstringconverter.h> #ifdef Q_OS_VXWORKS # include <selectLib.h> #endif +using namespace std::chrono_literals; + #define QT_CONNECT_TIMEOUT 30000 @@ -585,21 +587,22 @@ bool QLocalSocket::waitForConnected(int msec) if (state() != ConnectingState) return (state() == ConnectedState); - QElapsedTimer timer; - timer.start(); - pollfd pfd = qt_make_pollfd(d->connectingSocket, POLLIN); + QDeadlineTimer deadline{msec}; + auto remainingTime = deadline.remainingTimeAsDuration(); + do { - const int timeout = (msec > 0) ? qMax(msec - timer.elapsed(), Q_INT64_C(0)) : msec; - const int result = qt_poll_msecs(&pfd, 1, timeout); + timespec ts = durationToTimespec(remainingTime); + const int result = qt_safe_poll(&pfd, 1, &ts); if (result == -1) d->setErrorAndEmit(QLocalSocket::UnknownSocketError, "QLocalSocket::waitForConnected"_L1); else if (result > 0) d->_q_connectToSocket(); - } while (state() == ConnectingState && !timer.hasExpired(msec)); + } while (state() == ConnectingState + && (remainingTime = deadline.remainingTimeAsDuration()) > 0ns); return (state() == ConnectedState); } |