From 2e49b7a3b99a0f02c2521656fa2f573c2ea40150 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Wed, 19 Feb 2014 11:01:00 +0100 Subject: 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 Reviewed-by: Rafael Roquetto Reviewed-by: Thiago Macieira --- src/corelib/kernel/qcore_unix.cpp | 43 +++++++++++++++++++++++++++++++++++++++ src/corelib/kernel/qcore_unix_p.h | 8 ++++++++ 2 files changed, 51 insertions(+) (limited to 'src/corelib/kernel') 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 #endif +#ifdef Q_OS_BLACKBERRY +#include +#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 socketNotifiers, int nfds, fd_set *fdread, fd_set *fdwrite, + int timeout) +{ + QList 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 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; -- cgit v1.2.3