Blame SOURCES/qt-4.8-poll.patch

402b94
diff -up qt-everywhere-opensource-src-4.8.6/src/corelib/io/qprocess_unix.cpp.poll qt-everywhere-opensource-src-4.8.6/src/corelib/io/qprocess_unix.cpp
402b94
--- qt-everywhere-opensource-src-4.8.6/src/corelib/io/qprocess_unix.cpp.poll	2014-03-30 15:36:48.000000000 -0500
402b94
+++ qt-everywhere-opensource-src-4.8.6/src/corelib/io/qprocess_unix.cpp	2014-03-31 18:04:05.958260978 -0500
402b94
@@ -158,13 +158,6 @@ static void qt_sa_sigchld_sigaction(int
402b94
     }
2060a3
 }
2060a3
 
2060a3
-static inline void add_fd(int &nfds, int fd, fd_set *fdset)
2060a3
-{
2060a3
-    FD_SET(fd, fdset);
2060a3
-    if ((fd) > nfds)
2060a3
-        nfds = fd;
2060a3
-}
2060a3
-
2060a3
 struct QProcessInfo {
2060a3
     QProcess *process;
2060a3
     int deathPipe;
402b94
@@ -256,9 +249,9 @@ QProcessManager::~QProcessManager()
2060a3
 void QProcessManager::run()
2060a3
 {
2060a3
     forever {
2060a3
-        fd_set readset;
2060a3
-        FD_ZERO(&readset);
2060a3
-        FD_SET(qt_qprocess_deadChild_pipe[0], &readset);
2060a3
+	pollfd fd;
2060a3
+	fd.fd = qt_qprocess_deadChild_pipe[0];
2060a3
+	fd.events = POLLIN;
2060a3
 
2060a3
 #if defined (QPROCESS_DEBUG)
2060a3
         qDebug() << "QProcessManager::run() waiting for children to die";
402b94
@@ -267,8 +260,8 @@ void QProcessManager::run()
2060a3
         // block forever, or until activity is detected on the dead child
2060a3
         // pipe. the only other peers are the SIGCHLD signal handler, and the
2060a3
         // QProcessManager destructor.
2060a3
-        int nselect = select(qt_qprocess_deadChild_pipe[0] + 1, &readset, 0, 0, 0);
2060a3
-        if (nselect < 0) {
2060a3
+        int ret = qt_safe_poll(&fd, 1, -1, /* retry_eintr */ false);
2060a3
+        if (ret < 0) {
2060a3
             if (errno == EINTR)
2060a3
                 continue;
2060a3
             break;
402b94
@@ -1027,17 +1020,6 @@ void QProcessPrivate::killProcess()
2060a3
         ::kill(pid_t(pid), SIGKILL);
2060a3
 }
2060a3
 
2060a3
-static int select_msecs(int nfds, fd_set *fdread, fd_set *fdwrite, int timeout)
2060a3
-{
2060a3
-    if (timeout < 0)
2060a3
-        return qt_safe_select(nfds, fdread, fdwrite, 0, 0);
2060a3
-
2060a3
-    struct timeval tv;
2060a3
-    tv.tv_sec = timeout / 1000;
2060a3
-    tv.tv_usec = (timeout % 1000) * 1000;
2060a3
-    return qt_safe_select(nfds, fdread, fdwrite, 0, &tv;;
2060a3
-}
2060a3
-
2060a3
 /*
2060a3
    Returns the difference between msecs and elapsed. If msecs is -1,
2060a3
    however, -1 is returned.
402b94
@@ -1060,10 +1042,10 @@ bool QProcessPrivate::waitForStarted(int
2060a3
 	   childStartedPipe[0]);
2060a3
 #endif
2060a3
 
2060a3
-    fd_set fds;
2060a3
-    FD_ZERO(&fds);
2060a3
-    FD_SET(childStartedPipe[0], &fds);
2060a3
-    if (select_msecs(childStartedPipe[0] + 1, &fds, 0, msecs) == 0) {
2060a3
+    pollfd fd;
2060a3
+    fd.fd = childStartedPipe[0];
2060a3
+    fd.events = POLLIN;
2060a3
+    if (qt_safe_poll(&fd, 1, msecs) == 0) {
2060a3
         processError = QProcess::Timedout;
2060a3
         q->setErrorString(QProcess::tr("Process operation timed out"));
2060a3
 #if defined (QPROCESS_DEBUG)
402b94
@@ -1079,6 +1061,47 @@ bool QProcessPrivate::waitForStarted(int
2060a3
     return startedEmitted;
2060a3
 }
2060a3
 
2060a3
+class QProcessFDSet {
2060a3
+    pollfd fds[5];
2060a3
+
2060a3
+    static size_t size()
2060a3
+    {
2060a3
+	return sizeof(fds)/sizeof(fds[0]);
2060a3
+    }
2060a3
+
2060a3
+public:
2060a3
+    QProcessFDSet(QProcessPrivate &proc)
2060a3
+    {
2060a3
+	for (size_t i = 0; i < size(); ++i) {
2060a3
+	    fds[i].fd = -1;
2060a3
+	    fds[i].events = POLLIN;
2060a3
+	}
2060a3
+	death().fd = proc.deathPipe[0];
2060a3
+
2060a3
+        if (proc.processState == QProcess::Starting)
2060a3
+	    started().fd = proc.childStartedPipe[0];
2060a3
+
2060a3
+	stdout().fd = proc.stdoutChannel.pipe[0];
2060a3
+	stderr().fd = proc.stderrChannel.pipe[0];
2060a3
+
2060a3
+        if (!proc.writeBuffer.isEmpty()) {
2060a3
+	    stdin().fd = proc.stdinChannel.pipe[1];
2060a3
+	    stdin().events = POLLOUT;
2060a3
+	}
2060a3
+    }
2060a3
+
2060a3
+    int poll(int timeout)
2060a3
+    {
2060a3
+	return qt_safe_poll(fds, size(), timeout);
2060a3
+    }
2060a3
+
2060a3
+    pollfd &death() { return fds[0]; }
2060a3
+    pollfd &started() { return fds[1]; }
2060a3
+    pollfd &stdout() { return fds[2]; }
2060a3
+    pollfd &stderr() { return fds[3]; }
2060a3
+    pollfd &stdin() { return fds[4]; }
2060a3
+};
2060a3
+
2060a3
 bool QProcessPrivate::waitForReadyRead(int msecs)
2060a3
 {
2060a3
     Q_Q(QProcess);
402b94
@@ -1090,28 +1113,9 @@ bool QProcessPrivate::waitForReadyRead(i
2060a3
     stopWatch.start();
2060a3
 
2060a3
     forever {
2060a3
-        fd_set fdread;
2060a3
-        fd_set fdwrite;
2060a3
-
2060a3
-        FD_ZERO(&fdread);
2060a3
-        FD_ZERO(&fdwrite);
2060a3
-
2060a3
-        int nfds = deathPipe[0];
2060a3
-        FD_SET(deathPipe[0], &fdread);
2060a3
-
2060a3
-        if (processState == QProcess::Starting)
2060a3
-            add_fd(nfds, childStartedPipe[0], &fdread);
2060a3
-
2060a3
-        if (stdoutChannel.pipe[0] != -1)
2060a3
-            add_fd(nfds, stdoutChannel.pipe[0], &fdread);
2060a3
-        if (stderrChannel.pipe[0] != -1)
2060a3
-            add_fd(nfds, stderrChannel.pipe[0], &fdread);
2060a3
-
2060a3
-        if (!writeBuffer.isEmpty() && stdinChannel.pipe[1] != -1)
2060a3
-            add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
2060a3
-
2060a3
+	QProcessFDSet fdset(*this);
2060a3
         int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
2060a3
-        int ret = select_msecs(nfds + 1, &fdread, &fdwrite, timeout);
2060a3
+        int ret = fdset.poll(timeout);
2060a3
         if (ret < 0) {
2060a3
             break;
2060a3
         }
402b94
@@ -1121,18 +1125,18 @@ bool QProcessPrivate::waitForReadyRead(i
2060a3
 	    return false;
2060a3
 	}
2060a3
 
2060a3
-	if (childStartedPipe[0] != -1 && FD_ISSET(childStartedPipe[0], &fdread)) {
2060a3
+	if (qt_readable(fdset.started())) {
2060a3
             if (!_q_startupNotification())
2060a3
                 return false;
2060a3
 	}
2060a3
 
2060a3
         bool readyReadEmitted = false;
2060a3
-	if (stdoutChannel.pipe[0] != -1 && FD_ISSET(stdoutChannel.pipe[0], &fdread)) {
2060a3
+	if (qt_readable(fdset.stdout())) {
2060a3
 	    bool canRead = _q_canReadStandardOutput();
2060a3
             if (processChannel == QProcess::StandardOutput && canRead)
2060a3
                 readyReadEmitted = true;
2060a3
 	}
2060a3
-	if (stderrChannel.pipe[0] != -1 && FD_ISSET(stderrChannel.pipe[0], &fdread)) {
2060a3
+	if (qt_readable(fdset.stderr())) {
2060a3
 	    bool canRead = _q_canReadStandardError();
2060a3
             if (processChannel == QProcess::StandardError && canRead)
2060a3
                 readyReadEmitted = true;
402b94
@@ -1140,13 +1144,13 @@ bool QProcessPrivate::waitForReadyRead(i
2060a3
         if (readyReadEmitted)
2060a3
             return true;
2060a3
 
2060a3
-	if (stdinChannel.pipe[1] != -1 && FD_ISSET(stdinChannel.pipe[1], &fdwrite))
2060a3
+	if (qt_writable(fdset.stdin()))
2060a3
 	    _q_canWrite();
2060a3
 
2060a3
-	if (deathPipe[0] == -1 || FD_ISSET(deathPipe[0], &fdread)) {
2060a3
+	if (qt_readable(fdset.death())) {
2060a3
             if (_q_processDied())
2060a3
                 return false;
2060a3
-        }
2060a3
+	}
2060a3
     }
2060a3
     return false;
2060a3
 }
402b94
@@ -1162,29 +1166,9 @@ bool QProcessPrivate::waitForBytesWritte
2060a3
     stopWatch.start();
2060a3
 
2060a3
     while (!writeBuffer.isEmpty()) {
2060a3
-        fd_set fdread;
2060a3
-        fd_set fdwrite;
2060a3
-
2060a3
-        FD_ZERO(&fdread);
2060a3
-        FD_ZERO(&fdwrite);
2060a3
-
2060a3
-        int nfds = deathPipe[0];
2060a3
-        FD_SET(deathPipe[0], &fdread);
2060a3
-
2060a3
-        if (processState == QProcess::Starting)
2060a3
-            add_fd(nfds, childStartedPipe[0], &fdread);
2060a3
-
2060a3
-        if (stdoutChannel.pipe[0] != -1)
2060a3
-            add_fd(nfds, stdoutChannel.pipe[0], &fdread);
2060a3
-        if (stderrChannel.pipe[0] != -1)
2060a3
-            add_fd(nfds, stderrChannel.pipe[0], &fdread);
2060a3
-
2060a3
-
2060a3
-        if (!writeBuffer.isEmpty() && stdinChannel.pipe[1] != -1)
2060a3
-            add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
2060a3
-
2060a3
+	QProcessFDSet fdset(*this);
2060a3
 	int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
2060a3
-	int ret = select_msecs(nfds + 1, &fdread, &fdwrite, timeout);
2060a3
+	int ret = fdset.poll(timeout);
2060a3
         if (ret < 0) {
2060a3
             break;
2060a3
         }
402b94
@@ -1195,24 +1179,24 @@ bool QProcessPrivate::waitForBytesWritte
2060a3
 	    return false;
2060a3
 	}
2060a3
 
2060a3
-	if (childStartedPipe[0] != -1 && FD_ISSET(childStartedPipe[0], &fdread)) {
2060a3
+	if (qt_readable(fdset.started())) {
2060a3
 	    if (!_q_startupNotification())
2060a3
 		return false;
2060a3
 	}
2060a3
 
2060a3
-	if (stdinChannel.pipe[1] != -1 && FD_ISSET(stdinChannel.pipe[1], &fdwrite))
2060a3
+	if (qt_writable(fdset.stdin()))
2060a3
 	    return _q_canWrite();
2060a3
 
2060a3
-	if (stdoutChannel.pipe[0] != -1 && FD_ISSET(stdoutChannel.pipe[0], &fdread))
2060a3
+	if (qt_readable(fdset.stdout()))
2060a3
 	    _q_canReadStandardOutput();
2060a3
 
2060a3
-	if (stderrChannel.pipe[0] != -1 && FD_ISSET(stderrChannel.pipe[0], &fdread))
2060a3
+	if (qt_readable(fdset.stderr()))
2060a3
 	    _q_canReadStandardError();
2060a3
 
2060a3
-	if (deathPipe[0] == -1 || FD_ISSET(deathPipe[0], &fdread)) {
2060a3
-            if (_q_processDied())
2060a3
-                return false;
2060a3
-        }
2060a3
+	if (qt_readable(fdset.death())) {
2060a3
+	    if (_q_processDied())
2060a3
+		return false;
2060a3
+	}
2060a3
     }
2060a3
 
2060a3
     return false;
402b94
@@ -1229,29 +1213,9 @@ bool QProcessPrivate::waitForFinished(in
2060a3
     stopWatch.start();
2060a3
 
2060a3
     forever {
2060a3
-        fd_set fdread;
2060a3
-        fd_set fdwrite;
2060a3
-        int nfds = -1;
2060a3
-
2060a3
-        FD_ZERO(&fdread);
2060a3
-        FD_ZERO(&fdwrite);
2060a3
-
2060a3
-        if (processState == QProcess::Starting)
2060a3
-            add_fd(nfds, childStartedPipe[0], &fdread);
2060a3
-
2060a3
-        if (stdoutChannel.pipe[0] != -1)
2060a3
-            add_fd(nfds, stdoutChannel.pipe[0], &fdread);
2060a3
-        if (stderrChannel.pipe[0] != -1)
2060a3
-            add_fd(nfds, stderrChannel.pipe[0], &fdread);
2060a3
-
2060a3
-        if (processState == QProcess::Running)
2060a3
-            add_fd(nfds, deathPipe[0], &fdread);
2060a3
-
2060a3
-        if (!writeBuffer.isEmpty() && stdinChannel.pipe[1] != -1)
2060a3
-            add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
2060a3
-
2060a3
+	QProcessFDSet fdset(*this);
2060a3
 	int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
2060a3
-	int ret = select_msecs(nfds + 1, &fdread, &fdwrite, timeout);
2060a3
+	int ret = fdset.poll(timeout);
2060a3
         if (ret < 0) {
2060a3
             break;
2060a3
         }
402b94
@@ -1261,20 +1225,20 @@ bool QProcessPrivate::waitForFinished(in
2060a3
 	    return false;
2060a3
 	}
2060a3
 
2060a3
-	if (childStartedPipe[0] != -1 && FD_ISSET(childStartedPipe[0], &fdread)) {
2060a3
+	if (qt_readable(fdset.started())) {
2060a3
 	    if (!_q_startupNotification())
2060a3
 		return false;
2060a3
 	}
2060a3
-	if (stdinChannel.pipe[1] != -1 && FD_ISSET(stdinChannel.pipe[1], &fdwrite))
2060a3
+	if (qt_writable(fdset.stdin()))
2060a3
 	    _q_canWrite();
2060a3
 
2060a3
-	if (stdoutChannel.pipe[0] != -1 && FD_ISSET(stdoutChannel.pipe[0], &fdread))
2060a3
+	if (qt_readable(fdset.stdout()))
2060a3
 	    _q_canReadStandardOutput();
2060a3
 
2060a3
-	if (stderrChannel.pipe[0] != -1 && FD_ISSET(stderrChannel.pipe[0], &fdread))
2060a3
+	if (qt_readable(fdset.stderr()))
2060a3
 	    _q_canReadStandardError();
2060a3
 
2060a3
-	if (deathPipe[0] == -1 || FD_ISSET(deathPipe[0], &fdread)) {
2060a3
+	if (qt_readable(fdset.death())) {
2060a3
             if (_q_processDied())
2060a3
                 return true;
2060a3
 	}
402b94
@@ -1284,10 +1248,10 @@ bool QProcessPrivate::waitForFinished(in
2060a3
 
2060a3
 bool QProcessPrivate::waitForWrite(int msecs)
2060a3
 {
2060a3
-    fd_set fdwrite;
2060a3
-    FD_ZERO(&fdwrite);
2060a3
-    FD_SET(stdinChannel.pipe[1], &fdwrite);
2060a3
-    return select_msecs(stdinChannel.pipe[1] + 1, 0, &fdwrite, msecs < 0 ? 0 : msecs) == 1;
2060a3
+    pollfd fd;
2060a3
+    fd.fd = stdinChannel.pipe[1];
2060a3
+    fd.events = POLLIN;
2060a3
+    return qt_safe_poll(&fd, 1, msecs);
2060a3
 }
2060a3
 
2060a3
 void QProcessPrivate::findExitCode()
402b94
diff -up qt-everywhere-opensource-src-4.8.6/src/corelib/kernel/qcore_unix.cpp.poll qt-everywhere-opensource-src-4.8.6/src/corelib/kernel/qcore_unix.cpp
402b94
--- qt-everywhere-opensource-src-4.8.6/src/corelib/kernel/qcore_unix.cpp.poll	2014-03-30 15:36:48.000000000 -0500
402b94
+++ qt-everywhere-opensource-src-4.8.6/src/corelib/kernel/qcore_unix.cpp	2014-03-31 18:01:59.369715403 -0500
402b94
@@ -99,4 +99,165 @@ int qt_safe_select(int nfds, fd_set *fdr
2060a3
     }
2060a3
 }
2060a3
 
2060a3
+#ifndef Q_OS_VXWORKS
2060a3
+
2060a3
+int qt_safe_poll(struct pollfd *fds, int nfds, int timeout_ms, bool retry_eintr)
2060a3
+{
2060a3
+    if (nfds == 0)
2060a3
+	return 0;
2060a3
+    if (nfds < 0) {
2060a3
+	errno = EINVAL;
2060a3
+	return -1;
2060a3
+    }
2060a3
+
2060a3
+    // Retry on ret == 0 if the deadline has not yet passed because
2060a3
+    // Linux can return early from the syscall, without setting EINTR.
2060a3
+    if (timeout_ms < 0) {
2060a3
+	forever {
2060a3
+	    int ret = ::poll(fds, nfds, -1);
2060a3
+	    if (ret > 0)
2060a3
+		return ret;
2060a3
+	    if (retry_eintr) {
2060a3
+		if (ret == 0 || ret == -1 && errno == EINTR) {
2060a3
+		    continue;
2060a3
+		} else {
2060a3
+		    return -1;
2060a3
+		}
2060a3
+	    }
2060a3
+	    if (ret == 0) {
2060a3
+		errno = EINTR;
2060a3
+		return -1;
2060a3
+	    }
2060a3
+	    return ret;
2060a3
+	}
2060a3
+    }
2060a3
+
2060a3
+    timeval previous = qt_gettime();
2060a3
+    timeval deadline = previous;
2060a3
+    deadline.tv_sec += timeout_ms / 1000;
2060a3
+    deadline.tv_usec += (timeout_ms % 1000) * 1000;
2060a3
+    if (deadline.tv_usec >= 1000000) {
2060a3
+	++deadline.tv_sec;
2060a3
+	deadline.tv_usec -= 1000000;
2060a3
+    }
2060a3
+    int remaining = timeout_ms;
2060a3
+
2060a3
+    forever {
2060a3
+	int ret = ::poll(fds, nfds, remaining);
2060a3
+	if (ret > 0)
2060a3
+	    return ret;
2060a3
+	timeval now = qt_gettime();
2060a3
+	if ((now.tv_sec > deadline.tv_sec // past deadline
2060a3
+	     || (now.tv_sec == deadline.tv_sec
2060a3
+		 && now.tv_usec >= deadline.tv_usec))
2060a3
+	    || (now.tv_sec < previous.tv_sec // time warp
2060a3
+		|| (now.tv_sec == previous.tv_sec
2060a3
+		    && now.tv_usec < previous.tv_usec))
2060a3
+	    || (ret < 0 && (errno != EINTR || !retry_eintr))) // other error
2060a3
+	    return ret;
2060a3
+	if (ret == 0 && !retry_eintr) {
2060a3
+	    errno = EINTR;
2060a3
+	    return -1;
2060a3
+	}
2060a3
+        remaining = (deadline.tv_sec - now.tv_sec) * 1000
2060a3
+		     + (deadline.tv_usec - now.tv_usec) / 1000;
2060a3
+	previous = now;
2060a3
+    }
2060a3
+}
2060a3
+
2060a3
+#else
2060a3
+
2060a3
+// Poll emulation for VxWorks.
2060a3
+
2060a3
+static int mark_bad_descriptors(pollfd *fds, int nfds)
2060a3
+{
2060a3
+    fd_set r;
2060a3
+    FD_ZERO(&r);
2060a3
+    struct timeval tv;
2060a3
+    tv.tv_sec = 0;
2060a3
+    tv.tv_usec = 0;
2060a3
+    int ret = 0;
2060a3
+
2060a3
+    // Check each descriptor invidually for badness.
2060a3
+    for (int i = 0; i < nfds; ++i) {
2060a3
+        pollfd &fd(fds[i]);
2060a3
+        if (fd.fd >= 0) {
2060a3
+            FD_SET(fd.fd, &r);
2060a3
+            int ret = qt_safe_select(fd.fd + 1, &r, NULL, NULL, &tv;;
2060a3
+            FD_CLR(fd.fd, &r);
2060a3
+            if (ret < 0 && errno == EBADF) {
2060a3
+                fd.revents = POLLNVAL;
2060a3
+                ++ret;
2060a3
+            }
2060a3
+        }
2060a3
+    }
2060a3
+    Q_ASSERT(ret > 0);
2060a3
+    return ret;
2060a3
+}
2060a3
+
2060a3
+int qt_safe_poll(pollfd *fds, int nfds, int timeout, bool retry_eintr)
2060a3
+{
2060a3
+    fd_set r, w;
2060a3
+    FD_ZERO(&r);
2060a3
+    FD_ZERO(&w);
2060a3
+    int maxfd = -1;
2060a3
+
2060a3
+    // Extract the watched descriptors.
2060a3
+    for (int i = 0; i < nfds; ++i) {
2060a3
+        pollfd &fd(fds[i]);
2060a3
+        if (fd.fd >= 0 && fd.fd < FD_SETSIZE) {
2060a3
+            if (fd.events & POLLIN) {
2060a3
+                FD_SET(fd.fd, &r);
2060a3
+                if (fd.fd > maxfd)
2060a3
+                    maxfd = fd.fd;
2060a3
+            }
2060a3
+            if (fd.events & POLLOUT) {
2060a3
+                FD_SET(fd.fd, &w);
2060a3
+                if (fd.fd > maxfd)
2060a3
+                    maxfd = fd.fd;
2060a3
+            }
2060a3
+        }
2060a3
+    }
2060a3
+
2060a3
+    // If timeout is negative, wait indefinitely for activity.
2060a3
+    timeval tv;
2060a3
+    timeval *ptv;
2060a3
+    if (timeout >= 0) {
2060a3
+        tv.tv_sec = timeout / 1000;
2060a3
+        tv.tv_usec = (timeout % 1000) * 1000;
2060a3
+        ptv = &tv;
2060a3
+    } else
2060a3
+        ptv = NULL;
2060a3
+
2060a3
+    int ret;
2060a3
+    if (retry_eintr)
2060a3
+        ret = qt_safe_select(maxfd + 1, &r, &w, NULL, ptv);
2060a3
+    else
2060a3
+        ret = ::select(maxfd + 1, &r, &w, NULL, ptv);
2060a3
+    if (ret < 0 && errno == EBADF) {
2060a3
+        return mark_bad_descriptors(fds, nfds);
2060a3
+    }
2060a3
+    if (ret <= 0)
2060a3
+        return ret;
2060a3
+
2060a3
+    // Set the revents flags.
2060a3
+    ret = 0;
2060a3
+    for (int i = 0; i < nfds; ++i) {
2060a3
+        pollfd &fd(fds[i]);
2060a3
+        fd.revents = 0;
2060a3
+        if (fd.fd >= 0 && fd.fd < FD_SETSIZE) {
2060a3
+            if ((fd.events & POLLIN) && FD_ISSET(fd.fd, &r))
2060a3
+                fd.revents |= POLLIN;
2060a3
+            if ((fd.events & POLLOUT) && FD_ISSET(fd.fd, &w))
2060a3
+                fd.revents |= POLLOUT;
2060a3
+            if (fd.revents)
2060a3
+                ++ret;
2060a3
+        }
2060a3
+    }
2060a3
+    Q_ASSERT(ret > 0);
2060a3
+    return ret;
2060a3
+}
2060a3
+
2060a3
+#endif
2060a3
+
2060a3
 QT_END_NAMESPACE
402b94
diff -up qt-everywhere-opensource-src-4.8.6/src/corelib/kernel/qcore_unix_p.h.poll qt-everywhere-opensource-src-4.8.6/src/corelib/kernel/qcore_unix_p.h
402b94
--- qt-everywhere-opensource-src-4.8.6/src/corelib/kernel/qcore_unix_p.h.poll	2014-03-30 15:36:48.000000000 -0500
402b94
+++ qt-everywhere-opensource-src-4.8.6/src/corelib/kernel/qcore_unix_p.h	2014-03-31 18:01:59.370715392 -0500
402b94
@@ -345,9 +345,42 @@ static inline pid_t qt_safe_waitpid(pid_
2060a3
 
2060a3
 timeval qt_gettime(); // in qelapsedtimer_mac.cpp or qtimestamp_unix.cpp
2060a3
 
2060a3
+// Deprecated due to FD_SETSIZE limitation, use qt_safe_poll instead.
2060a3
 Q_CORE_EXPORT int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept,
2060a3
                                  const struct timeval *tv);
2060a3
 
2060a3
+#ifndef Q_OS_VXWORKS
2060a3
+#include <poll.h>
2060a3
+#else
2060a3
+
2060a3
+// Poll emulation for VxWorks.
2060a3
+
2060a3
+struct pollfd {
2060a3
+  int fd;
2060a3
+  short events;
2060a3
+  short revents;
2060a3
+};
2060a3
+
2060a3
+#define POLLIN 1
2060a3
+#define POLLOUT 2
2060a3
+#define POLLERR 4
2060a3
+#define POLLHUP 8
2060a3
+#define POLLNVAL 16
2060a3
+#endif
2060a3
+
2060a3
+inline bool qt_readable(const pollfd &fd)
2060a3
+{
2060a3
+  return fd.fd >= 0 && (fd.revents & (POLLIN | POLLHUP | POLLERR | POLLNVAL)) != 0;
2060a3
+}
2060a3
+
2060a3
+inline bool qt_writable(const pollfd &fd)
2060a3
+{
2060a3
+  return fd.fd >= 0 && (fd.revents & (POLLOUT | POLLHUP | POLLERR | POLLNVAL)) != 0;
2060a3
+}
2060a3
+
2060a3
+Q_CORE_EXPORT int qt_safe_poll(pollfd *fds, int nfds, int timeout,
2060a3
+                               bool retry_eintr = true);
2060a3
+
2060a3
 // according to X/OPEN we have to define semun ourselves
2060a3
 // we use prefix as on some systems sem.h will have it
2060a3
 struct semid_ds;
402b94
diff -up qt-everywhere-opensource-src-4.8.6/src/network/socket/qlocalserver_unix.cpp.poll qt-everywhere-opensource-src-4.8.6/src/network/socket/qlocalserver_unix.cpp
402b94
--- qt-everywhere-opensource-src-4.8.6/src/network/socket/qlocalserver_unix.cpp.poll	2014-03-30 15:36:49.000000000 -0500
402b94
+++ qt-everywhere-opensource-src-4.8.6/src/network/socket/qlocalserver_unix.cpp	2014-03-31 18:01:59.370715392 -0500
402b94
@@ -208,16 +208,11 @@ void QLocalServerPrivate::_q_onNewConnec
2060a3
 
2060a3
 void QLocalServerPrivate::waitForNewConnection(int msec, bool *timedOut)
2060a3
 {
2060a3
-    fd_set readfds;
2060a3
-    FD_ZERO(&readfds);
2060a3
-    FD_SET(listenSocket, &readfds);
2060a3
+    struct pollfd fd;
2060a3
+    fd.fd = listenSocket;
2060a3
+    fd.events = POLLIN;
2060a3
 
2060a3
-    timeval timeout;
2060a3
-    timeout.tv_sec = msec / 1000;
2060a3
-    timeout.tv_usec = (msec % 1000) * 1000;
2060a3
-
2060a3
-    int result = -1;
2060a3
-    result = qt_safe_select(listenSocket + 1, &readfds, 0, 0, (msec == -1) ? 0 : &timeout);
2060a3
+    int result = qt_safe_poll(&fd, 1, msec);
2060a3
     if (-1 == result) {
2060a3
         setError(QLatin1String("QLocalServer::waitForNewConnection"));
2060a3
         closeServer();
402b94
diff -up qt-everywhere-opensource-src-4.8.6/src/network/socket/qlocalsocket_unix.cpp.poll qt-everywhere-opensource-src-4.8.6/src/network/socket/qlocalsocket_unix.cpp
402b94
--- qt-everywhere-opensource-src-4.8.6/src/network/socket/qlocalsocket_unix.cpp.poll	2014-03-30 15:36:49.000000000 -0500
402b94
+++ qt-everywhere-opensource-src-4.8.6/src/network/socket/qlocalsocket_unix.cpp	2014-03-31 18:01:59.370715392 -0500
402b94
@@ -56,10 +56,6 @@
2060a3
 #include <qdebug.h>
2060a3
 #include <qelapsedtimer.h>
2060a3
 
2060a3
-#ifdef Q_OS_VXWORKS
2060a3
-#  include <selectLib.h>
2060a3
-#endif
2060a3
-
2060a3
 #define QT_CONNECT_TIMEOUT 30000
2060a3
 
2060a3
 QT_BEGIN_NAMESPACE
402b94
@@ -520,32 +516,17 @@ bool QLocalSocket::waitForConnected(int
2060a3
     if (state() != ConnectingState)
2060a3
         return (state() == ConnectedState);
2060a3
 
2060a3
-    fd_set fds;
2060a3
-    FD_ZERO(&fds);
2060a3
-    FD_SET(d->connectingSocket, &fds);
2060a3
-
2060a3
-    timeval timeout;
2060a3
-    timeout.tv_sec = msec / 1000;
2060a3
-    timeout.tv_usec = (msec % 1000) * 1000;
2060a3
-
2060a3
-    // timeout can not be 0 or else select will return an error.
2060a3
-    if (0 == msec)
2060a3
-        timeout.tv_usec = 1000;
2060a3
+    pollfd fd;
2060a3
+    fd.fd = d->connectingSocket;
2060a3
+    fd.events = POLLIN | POLLOUT;
2060a3
 
2060a3
     int result = -1;
2060a3
     // on Linux timeout will be updated by select, but _not_ on other systems.
2060a3
     QElapsedTimer timer;
2060a3
+    int remaining = msec;
2060a3
     timer.start();
2060a3
-    while (state() == ConnectingState
2060a3
-           && (-1 == msec || timer.elapsed() < msec)) {
2060a3
-#ifdef Q_OS_SYMBIAN
2060a3
-        // On Symbian, ready-to-write is signaled when non-blocking socket
2060a3
-        // connect is finised. Is ready-to-read really used on other
2060a3
-        // UNIX paltforms when using non-blocking AF_UNIX socket?
2060a3
-        result = ::select(d->connectingSocket + 1, 0, &fds, 0, &timeout);
2060a3
-#else
2060a3
-        result = ::select(d->connectingSocket + 1, &fds, 0, 0, &timeout);
2060a3
-#endif
2060a3
+    while (state() == ConnectingState) {
2060a3
+        result = qt_safe_poll(&fd, 1, remaining, /* retry_eintr */ false);
2060a3
         if (-1 == result && errno != EINTR) {
2060a3
             d->errorOccurred( QLocalSocket::UnknownSocketError,
2060a3
                     QLatin1String("QLocalSocket::waitForConnected"));
402b94
@@ -553,6 +534,11 @@ bool QLocalSocket::waitForConnected(int
2060a3
         }
2060a3
         if (result > 0)
2060a3
             d->_q_connectToSocket();
2060a3
+        if (msec >= 0) {
2060a3
+            remaining = timer.elapsed() - msec;
2060a3
+            if (remaining < 0)
2060a3
+                break;
2060a3
+        }
2060a3
     }
2060a3
 
2060a3
     return (state() == ConnectedState);
402b94
diff -up qt-everywhere-opensource-src-4.8.6/src/network/socket/qnativesocketengine_unix.cpp.poll qt-everywhere-opensource-src-4.8.6/src/network/socket/qnativesocketengine_unix.cpp
402b94
--- qt-everywhere-opensource-src-4.8.6/src/network/socket/qnativesocketengine_unix.cpp.poll	2014-03-30 15:36:49.000000000 -0500
402b94
+++ qt-everywhere-opensource-src-4.8.6/src/network/socket/qnativesocketengine_unix.cpp	2014-03-31 18:01:59.371715381 -0500
402b94
@@ -1068,48 +1068,40 @@ qint64 QNativeSocketEnginePrivate::nativ
2060a3
 
2060a3
 int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool selectForRead) const
2060a3
 {
2060a3
-    fd_set fds;
2060a3
-    FD_ZERO(&fds);
2060a3
-    FD_SET(socketDescriptor, &fds);
2060a3
-
2060a3
-    struct timeval tv;
2060a3
-    tv.tv_sec = timeout / 1000;
2060a3
-    tv.tv_usec = (timeout % 1000) * 1000;
2060a3
-
2060a3
-    int retval;
2060a3
-    if (selectForRead)
2060a3
-        retval = qt_safe_select(socketDescriptor + 1, &fds, 0, 0, timeout < 0 ? 0 : &tv;;
2060a3
-    else
2060a3
-        retval = qt_safe_select(socketDescriptor + 1, 0, &fds, 0, timeout < 0 ? 0 : &tv;;
2060a3
-
2060a3
-    return retval;
2060a3
+    struct pollfd fd;
2060a3
+    fd.fd = socketDescriptor;
2060a3
+    if (selectForRead) {
2060a3
+	fd.events = POLLIN;
2060a3
+    } else {
2060a3
+	fd.events = POLLOUT;
2060a3
+    }
2060a3
+    return qt_safe_poll(&fd, 1, timeout);
2060a3
 }
2060a3
 
2060a3
 int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool checkRead, bool checkWrite,
2060a3
                        bool *selectForRead, bool *selectForWrite) const
2060a3
 {
2060a3
-    fd_set fdread;
2060a3
-    FD_ZERO(&fdread);
2060a3
+    struct pollfd fd;
2060a3
+    fd.fd = socketDescriptor;
2060a3
     if (checkRead)
2060a3
-        FD_SET(socketDescriptor, &fdread);
2060a3
-
2060a3
-    fd_set fdwrite;
2060a3
-    FD_ZERO(&fdwrite);
2060a3
+	fd.events =  POLLIN;
2060a3
+    else
2060a3
+	fd.events = 0;
2060a3
     if (checkWrite)
2060a3
-        FD_SET(socketDescriptor, &fdwrite);
2060a3
-
2060a3
-    struct timeval tv;
2060a3
-    tv.tv_sec = timeout / 1000;
2060a3
-    tv.tv_usec = (timeout % 1000) * 1000;
2060a3
-
2060a3
-    int ret;
2060a3
-    ret = qt_safe_select(socketDescriptor + 1, &fdread, &fdwrite, 0, timeout < 0 ? 0 : &tv;;
2060a3
-
2060a3
+	fd.events |= POLLOUT;
2060a3
+    int ret = qt_safe_poll(&fd, 1, timeout);
2060a3
     if (ret <= 0)
2060a3
-        return ret;
2060a3
-    *selectForRead = FD_ISSET(socketDescriptor, &fdread);
2060a3
-    *selectForWrite = FD_ISSET(socketDescriptor, &fdwrite);
2060a3
-
2060a3
+	return ret;
2060a3
+    bool r = (fd.revents & (POLLIN | POLLHUP | POLLERR)) != 0;
2060a3
+    bool w = (fd.revents & (POLLOUT | POLLHUP | POLLERR)) != 0;
2060a3
+    // Emulate the return value from select(2).
2060a3
+    ret = 0;
2060a3
+    if (r)
2060a3
+	++ret;
2060a3
+    if (w)
2060a3
+	++ret;
2060a3
+    *selectForRead = r;
2060a3
+    *selectForWrite = w;
2060a3
     return ret;
2060a3
 }
2060a3
 
402b94
diff -up qt-everywhere-opensource-src-4.8.6/src/qt3support/network/q3socketdevice_unix.cpp.poll qt-everywhere-opensource-src-4.8.6/src/qt3support/network/q3socketdevice_unix.cpp
402b94
--- qt-everywhere-opensource-src-4.8.6/src/qt3support/network/q3socketdevice_unix.cpp.poll	2014-03-30 15:36:49.000000000 -0500
402b94
+++ qt-everywhere-opensource-src-4.8.6/src/qt3support/network/q3socketdevice_unix.cpp	2014-03-31 18:01:59.371715381 -0500
402b94
@@ -68,6 +68,7 @@ static inline int qt_socket_socket(int d
2060a3
 #endif
2060a3
 
2060a3
 #include "q3socketdevice.h"
2060a3
+#include "private/qcore_unix_p.h"
2060a3
 
2060a3
 #ifndef QT_NO_NETWORK
2060a3
 
402b94
@@ -588,19 +589,10 @@ Q_LONG Q3SocketDevice::waitForMore( int
2060a3
 {
2060a3
     if ( !isValid() )
2060a3
 	return -1;
2060a3
-    if ( fd >= FD_SETSIZE )
2060a3
-	return -1;
2060a3
-
2060a3
-    fd_set fds;
2060a3
-    struct timeval tv;
2060a3
-
2060a3
-    FD_ZERO( &fds );
2060a3
-    FD_SET( fd, &fds );
2060a3
-
2060a3
-    tv.tv_sec = msecs / 1000;
2060a3
-    tv.tv_usec = (msecs % 1000) * 1000;
2060a3
 
2060a3
-    int rv = select( fd+1, &fds, 0, 0, msecs < 0 ? 0 : &tv );
2060a3
+    pollfd pfd;
2060a3
+    pfd.fd = fd;
2060a3
+    int rv = qt_safe_poll(&pfd, 1, msecs, /* retry_eintr */ false);
2060a3
 
2060a3
     if ( rv < 0 )
2060a3
 	return -1;
402b94
diff -up qt-everywhere-opensource-src-4.8.6/src/qt3support/other/q3process_unix.cpp.poll qt-everywhere-opensource-src-4.8.6/src/qt3support/other/q3process_unix.cpp
402b94
--- qt-everywhere-opensource-src-4.8.6/src/qt3support/other/q3process_unix.cpp.poll	2014-03-30 15:36:49.000000000 -0500
402b94
+++ qt-everywhere-opensource-src-4.8.6/src/qt3support/other/q3process_unix.cpp	2014-03-31 18:01:59.372715370 -0500
2060a3
@@ -981,13 +981,10 @@ bool Q3Process::isRunning() const
2060a3
 	// On heavy processing, the socket notifier for the sigchild might not
2060a3
 	// have found time to fire yet.
2060a3
 	if ( d->procManager && d->procManager->sigchldFd[1] < FD_SETSIZE ) {
2060a3
-	    fd_set fds;
2060a3
-	    struct timeval tv;
2060a3
-	    FD_ZERO( &fds );
2060a3
-	    FD_SET( d->procManager->sigchldFd[1], &fds );
2060a3
-	    tv.tv_sec = 0;
2060a3
-	    tv.tv_usec = 0;
2060a3
-	    if ( ::select( d->procManager->sigchldFd[1]+1, &fds, 0, 0, &tv ) > 0 )
2060a3
+	    pollfd fd;
2060a3
+	    fd.fd = d->procManager->sigchldFd[1];
2060a3
+	    fd.events = POLLIN;
2060a3
+	    if ( qt_safe_poll(&fd, 1, 0, /* retry_eintr */ false) > 0 )
2060a3
 		d->procManager->sigchldHnd( d->procManager->sigchldFd[1] );
2060a3
 	}
2060a3
 
2060a3
@@ -1124,29 +1121,21 @@ void Q3Process::socketRead( int fd )
2060a3
 	}
2060a3
     }
2060a3
 
2060a3
-    if ( fd < FD_SETSIZE ) {
2060a3
-	fd_set fds;
2060a3
-	struct timeval tv;
2060a3
-	FD_ZERO( &fds );
2060a3
-	FD_SET( fd, &fds );
2060a3
-	tv.tv_sec = 0;
2060a3
-	tv.tv_usec = 0;
2060a3
-	while ( ::select( fd+1, &fds, 0, 0, &tv ) > 0 ) {
2060a3
-	    // prepare for the next round
2060a3
-	    FD_ZERO( &fds );
2060a3
-	    FD_SET( fd, &fds );
2060a3
-	    // read data
2060a3
-	    ba = new QByteArray( basize );
2060a3
-	    n = ::read( fd, ba->data(), basize );
2060a3
-	    if ( n > 0 ) {
2060a3
-		ba->resize( n );
2060a3
-		buffer->append( ba );
2060a3
-		ba = 0;
2060a3
-	    } else {
2060a3
-		delete ba;
2060a3
-		ba = 0;
2060a3
-		break;
2060a3
-	    }
2060a3
+    pollfd pfd;
2060a3
+    pfd.fd = fd;
2060a3
+    pfd.events = POLLIN;
2060a3
+    while (qt_safe_poll(&pfd, 1, 0)) {
2060a3
+	// read data
2060a3
+	ba = new QByteArray( basize );
2060a3
+	n = ::read( fd, ba->data(), basize );
2060a3
+	if ( n > 0 ) {
2060a3
+	    ba->resize( n );
2060a3
+	    buffer->append( ba );
2060a3
+	    ba = 0;
2060a3
+	} else {
2060a3
+	    delete ba;
2060a3
+	    ba = 0;
2060a3
+	    break;
2060a3
 	}
2060a3
     }
2060a3