summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTijl Coosemans <tijl@coosemans.org>2010-11-26 09:11:11 (GMT)
committerJoão Abecasis <joao.abecasis@nokia.com>2010-11-26 09:11:11 (GMT)
commitb3b1ddf6f8dca6fa12817c74298ed9c80e173c7c (patch)
tree3c229da77bbb29db56a89e79778cd9356288f2c1
parentc6d4a2ca73ac57d47adee35d0d11c98c8b5130ee (diff)
downloadQt-b3b1ddf6f8dca6fa12817c74298ed9c80e173c7c.zip
Qt-b3b1ddf6f8dca6fa12817c74298ed9c80e173c7c.tar.gz
Qt-b3b1ddf6f8dca6fa12817c74298ed9c80e173c7c.tar.bz2
QKqueueFileSystemWatcherEngine: Use higher file descriptors.
A file descriptor is used for every path to be monitored, but descriptors below FD_SETSIZE (typically 1024) are precious, for use with select(2). To allow the application (and other parts of Qt) to use select(2), try to duplicate the descriptor returned by open(2) above FD_SETSIZE and close(2) the original. However, only do so when the descriptor table is already fairly large (FD_SETSIZE / 2). This keeps the descriptor table small for applications that use only a few descriptors. While here, also set the close-on-exec flag on the (new) descriptor. Merge-request: 2425 Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
-rw-r--r--src/corelib/io/qfilesystemwatcher_kqueue.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/corelib/io/qfilesystemwatcher_kqueue.cpp b/src/corelib/io/qfilesystemwatcher_kqueue.cpp
index 29cd111..242c153 100644
--- a/src/corelib/io/qfilesystemwatcher_kqueue.cpp
+++ b/src/corelib/io/qfilesystemwatcher_kqueue.cpp
@@ -136,6 +136,14 @@ QStringList QKqueueFileSystemWatcherEngine::addPaths(const QStringList &paths,
perror("QKqueueFileSystemWatcherEngine::addPaths: open");
continue;
}
+ if (fd >= (int)FD_SETSIZE / 2 && fd < (int)FD_SETSIZE) {
+ int fddup = fcntl(fd, F_DUPFD, FD_SETSIZE);
+ if (fddup != -1) {
+ ::close(fd);
+ fd = fddup;
+ }
+ }
+ fcntl(fd, F_SETFD, FD_CLOEXEC);
QT_STATBUF st;
if (QT_FSTAT(fd, &st) == -1) {