From 1bfcbf12c47cba83bf51d937ed4ecdbc365758fd Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Wed, 3 Feb 2021 01:36:30 +0200 Subject: [PATCH] obtain open files limit via sysconf() Signed-off-by: Ivailo Monev --- src/core/kernel/qeventdispatcher_unix.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/core/kernel/qeventdispatcher_unix.cpp b/src/core/kernel/qeventdispatcher_unix.cpp index c3ac015ce..b65a16334 100644 --- a/src/core/kernel/qeventdispatcher_unix.cpp +++ b/src/core/kernel/qeventdispatcher_unix.cpp @@ -49,6 +49,10 @@ QT_BEGIN_NAMESPACE +#ifndef QT_NO_DEBUG +static const long maxOpenFiles = sysconf(_SC_OPEN_MAX); +#endif + QEventDispatcherUNIXPrivate::QEventDispatcherUNIXPrivate() : sn_highest(-1), interrupt(false) @@ -599,12 +603,10 @@ void QEventDispatcherUNIX::registerSocketNotifier(QSocketNotifier *notifier) int sockfd = notifier->socket(); int type = notifier->type(); #ifndef QT_NO_DEBUG - if (sockfd < 0 - || unsigned(sockfd) >= FD_SETSIZE) { + if (Q_UNLIKELY(sockfd < 0 || sockfd >= maxOpenFiles)) { qWarning("QSocketNotifier: Internal error"); return; - } else if (notifier->thread() != thread() - || thread() != QThread::currentThread()) { + } else if (Q_UNLIKELY(notifier->thread() != thread() || thread() != QThread::currentThread())) { qWarning("QSocketNotifier: socket notifiers cannot be enabled from another thread"); return; } @@ -642,12 +644,10 @@ void QEventDispatcherUNIX::unregisterSocketNotifier(QSocketNotifier *notifier) int sockfd = notifier->socket(); int type = notifier->type(); #ifndef QT_NO_DEBUG - if (sockfd < 0 - || unsigned(sockfd) >= FD_SETSIZE) { + if (Q_UNLIKELY(sockfd < 0 || sockfd >= maxOpenFiles)) { qWarning("QSocketNotifier: Internal error"); return; - } else if (notifier->thread() != thread() - || thread() != QThread::currentThread()) { + } else if (Q_UNLIKELY(notifier->thread() != thread() || thread() != QThread::currentThread())) { qWarning("QSocketNotifier: socket notifiers cannot be disabled from another thread"); return; } @@ -692,8 +692,7 @@ void QEventDispatcherUNIX::setSocketNotifierPending(QSocketNotifier *notifier) int sockfd = notifier->socket(); int type = notifier->type(); #ifndef QT_NO_DEBUG - if (sockfd < 0 - || unsigned(sockfd) >= FD_SETSIZE) { + if (Q_UNLIKELY(sockfd < 0 || sockfd >= maxOpenFiles)) { qWarning("QSocketNotifier: Internal error"); return; } -- 2.11.0