| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/kernel/qcore_unix.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Copyright (C) 2016 Intel Corporation. | - | ||||||||||||
| 5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
| 6 | ** | - | ||||||||||||
| 7 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||
| 8 | ** | - | ||||||||||||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
| 10 | ** Commercial License Usage | - | ||||||||||||
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
| 12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
| 13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
| 14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
| 15 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 16 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
| 17 | ** | - | ||||||||||||
| 18 | ** GNU Lesser General Public License Usage | - | ||||||||||||
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 20 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
| 22 | ** packaging of this file. Please review the following information to | - | ||||||||||||
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
| 25 | ** | - | ||||||||||||
| 26 | ** GNU General Public License Usage | - | ||||||||||||
| 27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
| 28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
| 29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
| 30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
| 32 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
| 33 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
| 36 | ** | - | ||||||||||||
| 37 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 38 | ** | - | ||||||||||||
| 39 | ****************************************************************************/ | - | ||||||||||||
| 40 | - | |||||||||||||
| 41 | #include "qcore_unix_p.h" | - | ||||||||||||
| 42 | #include "qelapsedtimer.h" | - | ||||||||||||
| 43 | - | |||||||||||||
| 44 | #include <stdlib.h> | - | ||||||||||||
| 45 | - | |||||||||||||
| 46 | #ifdef Q_OS_MAC | - | ||||||||||||
| 47 | #include <mach/mach_time.h> | - | ||||||||||||
| #endif | ||||||||||||||
| #ifdef Q_OS_BLACKBERRY | ||||||||||||||
| #include <qsocketnotifier.h> | ||||||||||||||
| 48 | #endif | - | ||||||||||||
| 49 | - | |||||||||||||
| 50 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 51 | - | |||||||||||||
| 52 | #if !defined(QT_HAVE_PPOLL) && defined(QT_HAVE_POLLTS) | - | ||||||||||||
| 53 | # define ppoll pollts | - | ||||||||||||
| 54 | # define QT_HAVE_PPOLL | - | ||||||||||||
| 55 | #endif | - | ||||||||||||
| 56 | - | |||||||||||||
| 57 | static inline bool time_update(struct timespec *tv, const struct timespec &start, | - | ||||||||||||
| 58 | const struct timespec &timeout) | - | ||||||||||||
| 59 | { | - | ||||||||||||
| 60 | // clock source is (hopefully) monotonic, so we can recalculate how much timeout is left; | - | ||||||||||||
| 61 | // if it isn't monotonic, we'll simply hope that it hasn't jumped, because we have no alternative | - | ||||||||||||
| 62 | struct timespec now = qt_gettime(); | - | ||||||||||||
| 63 | *tv = timeout + start - now; | - | ||||||||||||
| 64 | return tv->tv_sec >= 0; | - | ||||||||||||
| 65 | } | - | ||||||||||||
| 66 | - | |||||||||||||
| 67 | #if !defined(QT_HAVE_PPOLL) && defined(QT_HAVE_POLL) | - | ||||||||||||
| 68 | static inline int qt_safe_selecttimespecToMillisecs(const struct timespec *ts) | - | ||||||||||||
| 69 | { | - | ||||||||||||
| 70 | return (ts == NULL) ? -1 : executed 324551 times by 56 tests: return (ts == __null) ? -1 : (ts->tv_sec * 1000) + (ts->tv_nsec / 1000000);Executed by:
| 324551 | ||||||||||||
| 71 | (ts->tv_sec * 1000) + executed 324551 times by 56 tests: (ts->tv_nsec / 1000000);return (ts == __null) ? -1 : (ts->tv_sec * 1000) + (ts->tv_nsec / 1000000);Executed by:
executed 324551 times by 56 tests: return (ts == __null) ? -1 : (ts->tv_sec * 1000) + (ts->tv_nsec / 1000000);Executed by:
| 324551 | ||||||||||||
| 72 | } | - | ||||||||||||
| 73 | #endif | - | ||||||||||||
| 74 | - | |||||||||||||
| 75 | // defined in qpoll.cpp | - | ||||||||||||
| 76 | int qt_poll(struct pollfd *fds, nfds_t nfds, fd_setconst struct timespec *fdreadtimeout_ts); | - | ||||||||||||
| 77 | - | |||||||||||||
| 78 | static inline int qt_ppoll(struct pollfd *fds, fd_setnfds_t nfds, const struct timespec *fdwritetimeout_ts) | - | ||||||||||||
| 79 | { | - | ||||||||||||
| 80 | #if defined(QT_HAVE_PPOLL) | - | ||||||||||||
| 81 | return ::ppoll(fds, fd_setnfds, timeout_ts, Q_NULLPTR); | - | ||||||||||||
| 82 | #elif defined(QT_HAVE_POLL) | - | ||||||||||||
| 83 | return ::poll(fds, nfds, timespecToMillisecs(timeout_ts)); executed 324551 times by 56 tests: return ::poll(fds, nfds, timespecToMillisecs(timeout_ts));Executed by:
| 324551 | ||||||||||||
| 84 | #else | - | ||||||||||||
| 85 | return qt_poll(fds, nfds, timeout_ts); | - | ||||||||||||
| 86 | #endif | - | ||||||||||||
| 87 | } | - | ||||||||||||
| 88 | - | |||||||||||||
| 89 | - | |||||||||||||
| 90 | /*! | - | ||||||||||||
| 91 | \internal | - | ||||||||||||
| 92 | - | |||||||||||||
| 93 | Behaves as close to POSIX poll(2) as practical but may be implemented | - | ||||||||||||
| 94 | using select(2) where necessary. In that case, returns -1 and sets errno | - | ||||||||||||
| 95 | to EINVAL if passed any descriptor greater than or equal to FD_SETSIZE. | - | ||||||||||||
| 96 | */ | - | ||||||||||||
| 97 | int qt_safe_poll(struct pollfd *fdexceptfds, nfds_t nfds, const struct timespec *orig_timeouttimeout_ts) | - | ||||||||||||
| 98 | { | - | ||||||||||||
| 99 | if (!orig_timeouttimeout_ts) {
| 765-321646 | ||||||||||||
| 100 | // no timeout -> block forever | - | ||||||||||||
| 101 | int ret; | - | ||||||||||||
| 102 | EINTR_LOOP(ret, selectqt_ppoll(nfds, fdread, fdwritefds, fdexceptnfds, 0Q_NULLPTR)); executed 797 times by 13 tests: end of blockExecuted by:
| 0-797 | ||||||||||||
| 103 | return ret; executed 765 times by 13 tests: return ret;Executed by:
| 765 | ||||||||||||
| 104 | } | - | ||||||||||||
| 105 | - | |||||||||||||
| 106 | timespec start = qt_gettime(); | - | ||||||||||||
| 107 | timespec timeout = *orig_timeouttimeout_ts; | - | ||||||||||||
| 108 | - | |||||||||||||
| 109 | // loop and recalculate the timeout as needed | - | ||||||||||||
| 110 | int ret;forever { | - | ||||||||||||
| 111 | #ifndef Q_OS_QNXconst int ret = ::pselectqt_ppoll(nfds, fdread, fdwrite, fdexcept, &timeoutfds, 0); | - | ||||||||||||
| #else | ||||||||||||||
| timeval timeoutVal; | ||||||||||||||
| timeoutVal.tv_sec = timeout.tv_sec; | ||||||||||||||
| timeoutVal.tv_usec = timeout.tv_nsec / 1000; | ||||||||||||||
| ret = ::select(nfds, fdread, fdwrite, fdexcept, &timeoutVal&timeout); | ||||||||||||||
| 112 | #endifif (ret != -1 || errno != EINTR)
| 0-321646 | ||||||||||||
| 113 | return ret; executed 321646 times by 53 tests: return ret;Executed by:
| 321646 | ||||||||||||
| 114 | - | |||||||||||||
| 115 | // recalculate the timeout | - | ||||||||||||
| 116 | if (!time_update(&timeout, start, *orig_timeouttimeout_ts)) {
| 0-2108 | ||||||||||||
| 117 | // timeout during update | - | ||||||||||||
| 118 | // or clock reset, fake timeout error | - | ||||||||||||
| 119 | return 0; never executed: return 0; | 0 | ||||||||||||
| } never executed: return 0; | ||||||||||||||
| } never executed: return 0; | ||||||||||||||
| } never executed: return 0; | ||||||||||||||
| int qt_select_msecs(int nfds, fd_set *fdread, fd_set *fdwrite, int timeout) never executed: return 0; | ||||||||||||||
| { never executed: return 0; | ||||||||||||||
| if (timeout < 0) never executed: return 0; | ||||||||||||||
| return qt_safe_select(nfds, fdread, fdwrite, 0, 0); never executed: return 0; | ||||||||||||||
| struct timespec tv; never executed: return 0; | ||||||||||||||
| tv.tv_sec = timeout / 1000; never executed: return 0; | ||||||||||||||
| tv.tv_nsec = (timeout % 1000) * 1000 * 1000; never executed: return qt_safe_select(nfds, fdread, fdwrite, 0, &tv);return 0;never executed: return 0; | ||||||||||||||
| } never executed: return 0; | ||||||||||||||
| #ifdef Q_OS_BLACKBERRY never executed: return 0; | ||||||||||||||
| int bb_select(QList<QSocketNotifier *> socketNotifiers, int nfds, fd_set *fdread, fd_set *fdwrite, never executed: return 0; | ||||||||||||||
| int timeout) never executed: return 0; | ||||||||||||||
| { never executed: return 0; | ||||||||||||||
| QList<bool> socketNotifiersEnabled; never executed: return 0; | ||||||||||||||
| socketNotifiersEnabled.reserve(socketNotifiers.count()); never executed: return 0; | ||||||||||||||
| for (int a = never executed: 0;return 0;never executed: return 0; | ||||||||||||||
| 120 | a < socketNotifiers.count(); ++a) { | - | ||||||||||||
| if (socketNotifiers.at(a) && socketNotifiers.at(a)->isEnabled()) { | ||||||||||||||
| socketNotifiersEnabled.append(true); | ||||||||||||||
| socketNotifiers.at(a)->setEnabled(false); | ||||||||||||||
| } else { | ||||||||||||||
| socketNotifiersEnabled.append(false); | ||||||||||||||
| }} | ||||||||||||||
| 121 | const int ret = qt_select_msecs(nfds, fdread, fdwrite, timeout); executed 2108 times by 24 tests: end of blockExecuted by:
| 2108 | ||||||||||||
| for (int a = 0; a < socketNotifiers.count(); ++a) { executed 2108 times by 24 tests: end of blockExecuted by:
| ||||||||||||||
| if (socketNotifiersEnabled.at(a) == true) executed 2108 times by 24 tests: end of blockExecuted by:
| ||||||||||||||
| socketNotifiers.at(a)->setEnabled(true); executed 2108 times by 24 tests: }end of blockExecuted by:
executed 2108 times by 24 tests: end of blockExecuted by:
| ||||||||||||||
| return ret; never executed: }#endif end of blocknever executed: end of block | ||||||||||||||
| 123 | - | |||||||||||||
| 124 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |