summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qeventdispatcher_unix_p.h
diff options
context:
space:
mode:
authorLouai Al-Khanji <louai.al-khanji@theqtcompany.com>2015-10-16 16:19:53 +0300
committerLouai Al-Khanji <louai.al-khanji@theqtcompany.com>2016-01-26 19:41:45 +0000
commitacbd79996d7dedd65cda98bd1b0f15690f0271e4 (patch)
treef0a2848e7403cda397f0ee11679d11ab5a5f3fa9 /src/corelib/kernel/qeventdispatcher_unix_p.h
parentf3060312c89344744832e3352fe4f53efcb94c9b (diff)
QEventDispatcherUNIX: Use poll instead of select
This allows us to support file descriptors >= FD_SETSIZE. Change-Id: I7e4a35333446a587cfd13c077fa5e19fa3d1abc4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qeventdispatcher_unix_p.h')
-rw-r--r--src/corelib/kernel/qeventdispatcher_unix_p.h90
1 files changed, 47 insertions, 43 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_unix_p.h b/src/corelib/kernel/qeventdispatcher_unix_p.h
index 0ed57d12f8..b401c07040 100644
--- a/src/corelib/kernel/qeventdispatcher_unix_p.h
+++ b/src/corelib/kernel/qeventdispatcher_unix_p.h
@@ -59,38 +59,22 @@
#include "QtCore/qvarlengtharray.h"
#include "private/qtimerinfo_unix_p.h"
-#if !defined(Q_OS_VXWORKS)
-# include <sys/time.h>
-# if (!defined(Q_OS_HPUX) || defined(__ia64)) && !defined(Q_OS_NACL)
-# include <sys/select.h>
-# endif
-#endif
-
QT_BEGIN_NAMESPACE
-struct QSockNot
-{
- QSocketNotifier *obj;
- int fd;
- fd_set *queue;
-};
+class QEventDispatcherUNIXPrivate;
-class QSockNotType
+struct Q_CORE_EXPORT QSocketNotifierSetUNIX Q_DECL_FINAL
{
-public:
- QSockNotType();
- ~QSockNotType();
-
- typedef QPodList<QSockNot*, 32> List;
+ inline QSocketNotifierSetUNIX() Q_DECL_NOTHROW;
- List list;
- fd_set select_fds;
- fd_set enabled_fds;
- fd_set pending_fds;
+ inline bool isEmpty() const Q_DECL_NOTHROW;
+ inline short events() const Q_DECL_NOTHROW;
+ QSocketNotifier *notifiers[3];
};
-class QEventDispatcherUNIXPrivate;
+Q_DECLARE_TYPEINFO(QSocketNotifierSetUNIX, Q_PRIMITIVE_TYPE);
+
class Q_CORE_EXPORT QEventDispatcherUNIX : public QAbstractEventDispatcher
{
@@ -120,15 +104,6 @@ public:
protected:
QEventDispatcherUNIX(QEventDispatcherUNIXPrivate &dd, QObject *parent = 0);
-
- void setSocketNotifierPending(QSocketNotifier *notifier);
-
- int activateTimers();
- int activateSocketNotifiers();
-
- virtual int select(int nfds,
- fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
- timespec *timeout);
};
class Q_CORE_EXPORT QEventDispatcherUNIXPrivate : public QAbstractEventDispatcherPrivate
@@ -139,28 +114,57 @@ public:
QEventDispatcherUNIXPrivate();
~QEventDispatcherUNIXPrivate();
- int doSelect(QEventLoop::ProcessEventsFlags flags, timespec *timeout);
- virtual int initThreadWakeUp() Q_DECL_FINAL;
- virtual int processThreadWakeUp(int nsel) Q_DECL_FINAL;
+ int processThreadWakeUp(const pollfd &pfd);
+
+ int activateTimers();
+
+ void markPendingSocketNotifiers();
+ int activateSocketNotifiers();
+ void setSocketNotifierPending(QSocketNotifier *notifier);
// note for eventfd(7) support:
// if thread_pipe[1] is -1, then eventfd(7) is in use and is stored in thread_pipe[0]
int thread_pipe[2];
- // highest fd for all socket notifiers
- int sn_highest;
- // 3 socket notifier types - read, write and exception
- QSockNotType sn_vec[3];
+ QVector<pollfd> pollfds;
- QTimerInfoList timerList;
+ QHash<int, QSocketNotifierSetUNIX> socketNotifiers;
+ QVector<QSocketNotifier *> pendingNotifiers;
- // pending socket notifiers list
- QSockNotType::List sn_pending_list;
+ QTimerInfoList timerList;
QAtomicInt wakeUps;
QAtomicInt interrupt; // bool
};
+inline QSocketNotifierSetUNIX::QSocketNotifierSetUNIX() Q_DECL_NOTHROW
+{
+ notifiers[0] = 0;
+ notifiers[1] = 0;
+ notifiers[2] = 0;
+}
+
+inline bool QSocketNotifierSetUNIX::isEmpty() const Q_DECL_NOTHROW
+{
+ return !notifiers[0] && !notifiers[1] && !notifiers[2];
+}
+
+inline short QSocketNotifierSetUNIX::events() const Q_DECL_NOTHROW
+{
+ short result = 0;
+
+ if (notifiers[0])
+ result |= POLLIN;
+
+ if (notifiers[1])
+ result |= POLLOUT;
+
+ if (notifiers[2])
+ result |= POLLPRI;
+
+ return result;
+}
+
QT_END_NAMESPACE
#endif // QEVENTDISPATCHER_UNIX_P_H