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