From: Ivailo Monev Date: Tue, 2 Feb 2021 23:36:30 +0000 (+0200) Subject: obtain open files limit via sysconf() X-Git-Tag: 4.12.0~2623 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=1bfcbf12c47cba83bf51d937ed4ecdbc365758fd;p=kde%2FKatie.git obtain open files limit via sysconf() Signed-off-by: Ivailo Monev --- 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; }