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 <errno.h>
|
||||||
|
|
||||||
#include <qdir.h>
|
#include <qdir.h>
|
||||||
|
#include <qdeadlinetimer.h>
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
#include <qelapsedtimer.h>
|
|
||||||
#include <qstringconverter.h>
|
#include <qstringconverter.h>
|
||||||
|
|
||||||
#ifdef Q_OS_VXWORKS
|
#ifdef Q_OS_VXWORKS
|
||||||
# include <selectLib.h>
|
# include <selectLib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
#define QT_CONNECT_TIMEOUT 30000
|
#define QT_CONNECT_TIMEOUT 30000
|
||||||
|
|
||||||
|
|
||||||
@ -585,21 +587,22 @@ bool QLocalSocket::waitForConnected(int msec)
|
|||||||
if (state() != ConnectingState)
|
if (state() != ConnectingState)
|
||||||
return (state() == ConnectedState);
|
return (state() == ConnectedState);
|
||||||
|
|
||||||
QElapsedTimer timer;
|
|
||||||
timer.start();
|
|
||||||
|
|
||||||
pollfd pfd = qt_make_pollfd(d->connectingSocket, POLLIN);
|
pollfd pfd = qt_make_pollfd(d->connectingSocket, POLLIN);
|
||||||
|
|
||||||
|
QDeadlineTimer deadline{msec};
|
||||||
|
auto remainingTime = deadline.remainingTimeAsDuration();
|
||||||
|
|
||||||
do {
|
do {
|
||||||
const int timeout = (msec > 0) ? qMax(msec - timer.elapsed(), Q_INT64_C(0)) : msec;
|
timespec ts = durationToTimespec(remainingTime);
|
||||||
const int result = qt_poll_msecs(&pfd, 1, timeout);
|
const int result = qt_safe_poll(&pfd, 1, &ts);
|
||||||
|
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
d->setErrorAndEmit(QLocalSocket::UnknownSocketError,
|
d->setErrorAndEmit(QLocalSocket::UnknownSocketError,
|
||||||
"QLocalSocket::waitForConnected"_L1);
|
"QLocalSocket::waitForConnected"_L1);
|
||||||
else if (result > 0)
|
else if (result > 0)
|
||||||
d->_q_connectToSocket();
|
d->_q_connectToSocket();
|
||||||
} while (state() == ConnectingState && !timer.hasExpired(msec));
|
} while (state() == ConnectingState
|
||||||
|
&& (remainingTime = deadline.remainingTimeAsDuration()) > 0ns);
|
||||||
|
|
||||||
return (state() == ConnectedState);
|
return (state() == ConnectedState);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user