summaryrefslogtreecommitdiffstats
path: root/src/network/socket
diff options
context:
space:
mode:
authorLouai Al-Khanji <louai.al-khanji@theqtcompany.com>2016-02-03 20:12:44 -0800
committerLouai Al-Khanji <louai.al-khanji@theqtcompany.com>2016-02-04 22:35:19 +0000
commit417586875fca4f596d7e5d485908237a6cb984b4 (patch)
treed0ff9699dd26d6a673f82006433ec8c950d5dcf6 /src/network/socket
parent180b60cc894ad878c5e61a1de2d13e769b2e6def (diff)
QLocalSocket: Use poll instead of select on Unix
Change-Id: I5399623d284ccd804bd1638da143ccdb973af9e2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/network/socket')
-rw-r--r--src/network/socket/qlocalsocket_unix.cpp35
1 files changed, 12 insertions, 23 deletions
diff --git a/src/network/socket/qlocalsocket_unix.cpp b/src/network/socket/qlocalsocket_unix.cpp
index 5c577512c3..c7997091a7 100644
--- a/src/network/socket/qlocalsocket_unix.cpp
+++ b/src/network/socket/qlocalsocket_unix.cpp
@@ -513,36 +513,25 @@ void QLocalSocket::setReadBufferSize(qint64 size)
bool QLocalSocket::waitForConnected(int msec)
{
Q_D(QLocalSocket);
+
if (state() != ConnectingState)
return (state() == ConnectedState);
- fd_set fds;
- FD_ZERO(&fds);
- FD_SET(d->connectingSocket, &fds);
+ QElapsedTimer timer;
+ timer.start();
- timeval timeout;
- timeout.tv_sec = msec / 1000;
- timeout.tv_usec = (msec % 1000) * 1000;
+ pollfd pfd = qt_make_pollfd(d->connectingSocket, POLLIN);
- // timeout can not be 0 or else select will return an error.
- if (0 == msec)
- timeout.tv_usec = 1000;
+ do {
+ const int timeout = (msec > 0) ? qMax(msec - timer.elapsed(), Q_INT64_C(0)) : msec;
+ const int result = qt_poll_msecs(&pfd, 1, timeout);
- int result = -1;
- // on Linux timeout will be updated by select, but _not_ on other systems.
- QElapsedTimer timer;
- timer.start();
- while (state() == ConnectingState
- && (-1 == msec || timer.elapsed() < msec)) {
- result = ::select(d->connectingSocket + 1, &fds, 0, 0, &timeout);
- if (-1 == result && errno != EINTR) {
- d->errorOccurred( QLocalSocket::UnknownSocketError,
- QLatin1String("QLocalSocket::waitForConnected"));
- break;
- }
- if (result > 0)
+ if (result == -1)
+ d->errorOccurred(QLocalSocket::UnknownSocketError,
+ QLatin1String("QLocalSocket::waitForConnected"));
+ else if (result > 0)
d->_q_connectToSocket();
- }
+ } while (state() == ConnectingState && !timer.hasExpired(msec));
return (state() == ConnectedState);
}