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 16:08:20 (GMT)
commitf7feeee1733b6cb8bfcc157fff1e444068dc290c (patch)
tree58cc03e30b29bc775104a515063a3bfa792c32f6
parente0e9d4ea2cec37243d964a5309be49101d112233 (diff)
downloadQt-f7feeee1733b6cb8bfcc157fff1e444068dc290c.zip
Qt-f7feeee1733b6cb8bfcc157fff1e444068dc290c.tar.gz
Qt-f7feeee1733b6cb8bfcc157fff1e444068dc290c.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 637a961..0103abd 100644
--- a/src/corelib/io/qfilesystemwatcher_kqueue.cpp
+++ b/src/corelib/io/qfilesystemwatcher_kqueue.cpp
@@ -134,6 +134,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) {