qcore_unix.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/kernel/qcore_unix.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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>-
48#endif-
49-
50QT_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-
57static 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;
executed 2108 times by 24 tests: return tv->tv_sec >= 0;
Executed by:
  • tst_Lancelot
  • tst_QApplication
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDir
  • tst_QFont
  • tst_QIcon
  • tst_QMimeDatabase
  • tst_QNetworkSession
  • tst_QObject
  • tst_QProcess
  • tst_QProcess_and_GuiEventLoop
  • tst_QSharedMemory
  • tst_QSharedPointer
  • tst_QSystemSemaphore
  • tst_QUuid
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qdbusxml2cpp
  • tst_qmessagehandler
  • tst_qprocess - unknown status
  • tst_rcc
  • tst_uic
2108
65}-
66-
67#if !defined(QT_HAVE_PPOLL) && defined(QT_HAVE_POLL)-
68static inline int timespecToMillisecs(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:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QApplication
  • tst_QCommandLineParser
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFont
  • tst_QFtp
  • tst_QGuiEventLoop
  • tst_QHttpSocketEngine
  • tst_QIODevice
  • tst_QIcon
  • tst_QLocalSocket
  • tst_QLockFile
  • tst_QMimeDatabase
  • tst_QNetworkInterface
  • tst_QNetworkReply
  • ...
324551
71 (ts->tv_sec * 1000) + (ts->tv_nsec / 1000000);
executed 324551 times by 56 tests: return (ts == __null) ? -1 : (ts->tv_sec * 1000) + (ts->tv_nsec / 1000000);
Executed by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QApplication
  • tst_QCommandLineParser
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFont
  • tst_QFtp
  • tst_QGuiEventLoop
  • tst_QHttpSocketEngine
  • tst_QIODevice
  • tst_QIcon
  • tst_QLocalSocket
  • tst_QLockFile
  • tst_QMimeDatabase
  • tst_QNetworkInterface
  • tst_QNetworkReply
  • ...
324551
72}-
73#endif-
74-
75// defined in qpoll.cpp-
76int qt_poll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts);-
77-
78static inline int qt_ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts)-
79{-
80#if defined(QT_HAVE_PPOLL)-
81 return ::ppoll(fds, nfds, 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:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QApplication
  • tst_QCommandLineParser
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFont
  • tst_QFtp
  • tst_QGuiEventLoop
  • tst_QHttpSocketEngine
  • tst_QIODevice
  • tst_QIcon
  • tst_QLocalSocket
  • tst_QLockFile
  • tst_QMimeDatabase
  • tst_QNetworkInterface
  • tst_QNetworkReply
  • ...
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*/-
97int qt_safe_poll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts)-
98{-
99 if (!timeout_ts) {
!timeout_tsDescription
TRUEevaluated 765 times by 13 tests
Evaluated by:
  • tst_QEventLoop
  • tst_QGuiEventLoop
  • tst_QLockFile
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QProcess
  • tst_QSslSocket
  • tst_QTcpSocket
  • tst_QUndoGroup
  • tst_QUndoStack
  • tst_QXmlSimpleReader
  • tst_qmake
  • tst_qmakelib
FALSEevaluated 321646 times by 52 tests
Evaluated by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QApplication
  • tst_QCommandLineParser
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFont
  • tst_QFtp
  • tst_QGuiEventLoop
  • tst_QHttpSocketEngine
  • tst_QIODevice
  • tst_QIcon
  • tst_QLocalSocket
  • tst_QLockFile
  • tst_QMimeDatabase
  • tst_QNetworkInterface
  • tst_QNetworkReply
  • ...
765-321646
100 // no timeout -> block forever-
101 int ret;-
102 EINTR_LOOP(ret, qt_ppoll(fds, nfds, Q_NULLPTR));
executed 797 times by 13 tests: end of block
Executed by:
  • tst_QEventLoop
  • tst_QGuiEventLoop
  • tst_QLockFile
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QProcess
  • tst_QSslSocket
  • tst_QTcpSocket
  • tst_QUndoGroup
  • tst_QUndoStack
  • tst_QXmlSimpleReader
  • tst_qmake
  • tst_qmakelib
ret == -1Description
TRUEevaluated 32 times by 3 tests
Evaluated by:
  • tst_QProcess
  • tst_qmake
  • tst_qmakelib
FALSEevaluated 765 times by 13 tests
Evaluated by:
  • tst_QEventLoop
  • tst_QGuiEventLoop
  • tst_QLockFile
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QProcess
  • tst_QSslSocket
  • tst_QTcpSocket
  • tst_QUndoGroup
  • tst_QUndoStack
  • tst_QXmlSimpleReader
  • tst_qmake
  • tst_qmakelib
(*__errno_location ()) == 4Description
TRUEevaluated 32 times by 3 tests
Evaluated by:
  • tst_QProcess
  • tst_qmake
  • tst_qmakelib
FALSEnever evaluated
0-797
103 return ret;
executed 765 times by 13 tests: return ret;
Executed by:
  • tst_QEventLoop
  • tst_QGuiEventLoop
  • tst_QLockFile
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QProcess
  • tst_QSslSocket
  • tst_QTcpSocket
  • tst_QUndoGroup
  • tst_QUndoStack
  • tst_QXmlSimpleReader
  • tst_qmake
  • tst_qmakelib
765
104 }-
105-
106 timespec start = qt_gettime();-
107 timespec timeout = *timeout_ts;-
108-
109 // loop and recalculate the timeout as needed-
110 forever {-
111 const int ret = qt_ppoll(fds, nfds, &timeout);-
112 if (ret != -1 || errno != EINTR)
ret != -1Description
TRUEevaluated 321646 times by 53 tests
Evaluated by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QApplication
  • tst_QCommandLineParser
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFont
  • tst_QFtp
  • tst_QGuiEventLoop
  • tst_QHttpSocketEngine
  • tst_QIODevice
  • tst_QIcon
  • tst_QLocalSocket
  • tst_QLockFile
  • tst_QMimeDatabase
  • tst_QNetworkInterface
  • tst_QNetworkReply
  • ...
FALSEevaluated 2108 times by 24 tests
Evaluated by:
  • tst_Lancelot
  • tst_QApplication
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDir
  • tst_QFont
  • tst_QIcon
  • tst_QMimeDatabase
  • tst_QNetworkSession
  • tst_QObject
  • tst_QProcess
  • tst_QProcess_and_GuiEventLoop
  • tst_QSharedMemory
  • tst_QSharedPointer
  • tst_QSystemSemaphore
  • tst_QUuid
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qdbusxml2cpp
  • tst_qmessagehandler
  • tst_qprocess - unknown status
  • tst_rcc
  • tst_uic
(*__errno_location ()) != 4Description
TRUEnever evaluated
FALSEevaluated 2108 times by 24 tests
Evaluated by:
  • tst_Lancelot
  • tst_QApplication
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDir
  • tst_QFont
  • tst_QIcon
  • tst_QMimeDatabase
  • tst_QNetworkSession
  • tst_QObject
  • tst_QProcess
  • tst_QProcess_and_GuiEventLoop
  • tst_QSharedMemory
  • tst_QSharedPointer
  • tst_QSystemSemaphore
  • tst_QUuid
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qdbusxml2cpp
  • tst_qmessagehandler
  • tst_qprocess - unknown status
  • tst_rcc
  • tst_uic
0-321646
113 return ret;
executed 321646 times by 53 tests: return ret;
Executed by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QApplication
  • tst_QCommandLineParser
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFont
  • tst_QFtp
  • tst_QGuiEventLoop
  • tst_QHttpSocketEngine
  • tst_QIODevice
  • tst_QIcon
  • tst_QLocalSocket
  • tst_QLockFile
  • tst_QMimeDatabase
  • tst_QNetworkInterface
  • tst_QNetworkReply
  • ...
321646
114-
115 // recalculate the timeout-
116 if (!time_update(&timeout, start, *timeout_ts)) {
!time_update(&..., *timeout_ts)Description
TRUEnever evaluated
FALSEevaluated 2108 times by 24 tests
Evaluated by:
  • tst_Lancelot
  • tst_QApplication
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDir
  • tst_QFont
  • tst_QIcon
  • tst_QMimeDatabase
  • tst_QNetworkSession
  • tst_QObject
  • tst_QProcess
  • tst_QProcess_and_GuiEventLoop
  • tst_QSharedMemory
  • tst_QSharedPointer
  • tst_QSystemSemaphore
  • tst_QUuid
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qdbusxml2cpp
  • tst_qmessagehandler
  • tst_qprocess - unknown status
  • tst_rcc
  • tst_uic
0-2108
117 // timeout during update-
118 // or clock reset, fake timeout error-
119 return 0;
never executed: return 0;
0
120 }-
121 }
executed 2108 times by 24 tests: end of block
Executed by:
  • tst_Lancelot
  • tst_QApplication
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDir
  • tst_QFont
  • tst_QIcon
  • tst_QMimeDatabase
  • tst_QNetworkSession
  • tst_QObject
  • tst_QProcess
  • tst_QProcess_and_GuiEventLoop
  • tst_QSharedMemory
  • tst_QSharedPointer
  • tst_QSystemSemaphore
  • tst_QUuid
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qdbusxml2cpp
  • tst_qmessagehandler
  • tst_qprocess - unknown status
  • tst_rcc
  • tst_uic
2108
122}
never executed: end of block
0
123-
124QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9