diff options
author | Peter Hartmann <phartmann@blackberry.com> | 2014-02-19 11:01:00 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-14 18:20:09 +0100 |
commit | 2e49b7a3b99a0f02c2521656fa2f573c2ea40150 (patch) | |
tree | 7a27b75d2af670d8e2615faa32dd1921aa11019f /src/corelib/kernel | |
parent | 4b8aee7ca089ecf7509bbbb2369cc15a6432ab03 (diff) |
BB select(): move special select method to qcore_unix_p.h
... and make it independent of QProcess, because we want to use it
from QtNetwork as well.
In addition, move select_msecs() to qcore_unix_p.h as well and rename
it to qt_select_msecs().
Task-number: QTBUG-36144
Change-Id: Ief681b6f6c80e85aa5091a5a04bcedb60f353217
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qcore_unix.cpp | 43 | ||||
-rw-r--r-- | src/corelib/kernel/qcore_unix_p.h | 8 |
2 files changed, 51 insertions, 0 deletions
diff --git a/src/corelib/kernel/qcore_unix.cpp b/src/corelib/kernel/qcore_unix.cpp index e4181b5c86..8d788419fb 100644 --- a/src/corelib/kernel/qcore_unix.cpp +++ b/src/corelib/kernel/qcore_unix.cpp @@ -58,6 +58,10 @@ #include <mach/mach_time.h> #endif +#ifdef Q_OS_BLACKBERRY +#include <qsocketnotifier.h> +#endif // Q_OS_BLACKBERRY + QT_BEGIN_NAMESPACE static inline bool time_update(struct timespec *tv, const struct timespec &start, @@ -106,4 +110,43 @@ int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept, } } +int qt_select_msecs(int nfds, fd_set *fdread, fd_set *fdwrite, int timeout) +{ + if (timeout < 0) + return qt_safe_select(nfds, fdread, fdwrite, 0, 0); + + struct timespec tv; + tv.tv_sec = timeout / 1000; + tv.tv_nsec = (timeout % 1000) * 1000 * 1000; + return qt_safe_select(nfds, fdread, fdwrite, 0, &tv); +} + +#ifdef Q_OS_BLACKBERRY +// The BlackBerry event dispatcher uses bps_get_event. Unfortunately, already registered +// socket notifiers are disabled by a call to select. This is to rearm the standard streams. +int bb_select(QList<QSocketNotifier *> socketNotifiers, int nfds, fd_set *fdread, fd_set *fdwrite, + int timeout) +{ + QList<bool> socketNotifiersEnabled; + socketNotifiersEnabled.reserve(socketNotifiers.count()); + for (int a = 0; a < socketNotifiers.count(); ++a) { + if (socketNotifiers.at(a) && socketNotifiers.at(a)->isEnabled()) { + socketNotifiersEnabled[a] = true; + socketNotifiers.at(a)->setEnabled(false); + } else { + socketNotifiersEnabled[a] = false; + } + } + + const int ret = qt_select_msecs(nfds, fdread, fdwrite, timeout); + + for (int a = 0; a < socketNotifiers.count(); ++a) { + if (socketNotifiersEnabled.at(a) == true) + socketNotifiers.at(a)->setEnabled(true); + } + + return ret; +} +#endif // Q_OS_BLACKBERRY + QT_END_NAMESPACE diff --git a/src/corelib/kernel/qcore_unix_p.h b/src/corelib/kernel/qcore_unix_p.h index 7ab632d7a0..df78ef6692 100644 --- a/src/corelib/kernel/qcore_unix_p.h +++ b/src/corelib/kernel/qcore_unix_p.h @@ -343,6 +343,14 @@ void qt_nanosleep(timespec amount); Q_CORE_EXPORT int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept, const struct timespec *tv); +int qt_select_msecs(int nfds, fd_set *fdread, fd_set *fdwrite, int timeout); + +#ifdef Q_OS_BLACKBERRY +class QSocketNotifier; +Q_CORE_EXPORT int bb_select(QList<QSocketNotifier *> socketNotifiers, int nfds, fd_set *fdread, + fd_set *fdwrite, int timeout); +#endif // Q_OS_BLACKBERRY + // according to X/OPEN we have to define semun ourselves // we use prefix as on some systems sem.h will have it struct semid_ds; |