QLocalSocket: port to QDeadlineTimer
Easier logic for such use-cases. Change-Id: I4ce14bbaeda5441294f33993195396d9f47710dc Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
6ecf43120f
commit
b358672556
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user