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) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtCore module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qcore_unix_p.h"-
35#include "qelapsedtimer.h"-
36-
37#include <stdlib.h>-
38-
39#ifdef Q_OS_MAC-
40#include <mach/mach_time.h>-
41#endif-
42-
43#ifdef Q_OS_BLACKBERRY-
44#include <qsocketnotifier.h>-
45#endif // Q_OS_BLACKBERRY-
46-
47QT_BEGIN_NAMESPACE-
48-
49static inline bool time_update(struct timespec *tv, const struct timespec &start,-
50 const struct timespec &timeout)-
51{-
52 // clock source is (hopefully) monotonic, so we can recalculate how much timeout is left;-
53 // if it isn't monotonic, we'll simply hope that it hasn't jumped, because we have no alternative-
54 struct timespec now = qt_gettime();-
55 *tv = timeout + start - now;-
56 return tv->tv_sec >= 0;
executed 1564 times by 23 tests: return tv->tv_sec >= 0;
Executed by:
  • tst_Lancelot
  • tst_QApplication
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDir
  • tst_QFont
  • 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
1564
57}-
58-
59int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept,-
60 const struct timespec *orig_timeout)-
61{-
62 if (!orig_timeout) {
!orig_timeoutDescription
TRUEevaluated 763 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 301848 times by 51 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_QLocalSocket
  • tst_QLockFile
  • tst_QMimeDatabase
  • tst_QNetworkInterface
  • tst_QNetworkReply
  • tst_QNetworkSession
  • ...
763-301848
63 // no timeout -> block forever-
64 int ret;-
65 EINTR_LOOP(ret, select(nfds, fdread, fdwrite, fdexcept, 0));
executed 795 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 763 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-795
66 return ret;
executed 763 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
763
67 }-
68-
69 timespec start = qt_gettime();-
70 timespec timeout = *orig_timeout;-
71-
72 // loop and recalculate the timeout as needed-
73 int ret;-
74 forever {-
75#ifndef Q_OS_QNX-
76 ret = ::pselect(nfds, fdread, fdwrite, fdexcept, &timeout, 0);-
77#else-
78 timeval timeoutVal;-
79 timeoutVal.tv_sec = timeout.tv_sec;-
80 timeoutVal.tv_usec = timeout.tv_nsec / 1000;-
81 ret = ::select(nfds, fdread, fdwrite, fdexcept, &timeoutVal);-
82#endif-
83 if (ret != -1 || errno != EINTR)
ret != -1Description
TRUEevaluated 301848 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_QLocalSocket
  • tst_QLockFile
  • tst_QMimeDatabase
  • tst_QNetworkInterface
  • tst_QNetworkReply
  • tst_QNetworkSession
  • ...
FALSEevaluated 1564 times by 23 tests
Evaluated by:
  • tst_Lancelot
  • tst_QApplication
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDir
  • tst_QFont
  • 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 1564 times by 23 tests
Evaluated by:
  • tst_Lancelot
  • tst_QApplication
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDir
  • tst_QFont
  • 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-301848
84 return ret;
executed 301848 times by 52 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_QLocalSocket
  • tst_QLockFile
  • tst_QMimeDatabase
  • tst_QNetworkInterface
  • tst_QNetworkReply
  • tst_QNetworkSession
  • ...
301848
85-
86 // recalculate the timeout-
87 if (!time_update(&timeout, start, *orig_timeout)) {
!time_update(&...*orig_timeout)Description
TRUEnever evaluated
FALSEevaluated 1564 times by 23 tests
Evaluated by:
  • tst_Lancelot
  • tst_QApplication
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDir
  • tst_QFont
  • 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-1564
88 // timeout during update-
89 // or clock reset, fake timeout error-
90 return 0;
never executed: return 0;
0
91 }-
92 }
executed 1564 times by 23 tests: end of block
Executed by:
  • tst_Lancelot
  • tst_QApplication
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDir
  • tst_QFont
  • 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
1564
93}
never executed: end of block
0
94-
95int qt_select_msecs(int nfds, fd_set *fdread, fd_set *fdwrite, int timeout)-
96{-
97 if (timeout < 0)
timeout < 0Description
TRUEevaluated 659 times by 6 tests
Evaluated by:
  • tst_QLockFile
  • tst_QProcess
  • tst_QUndoGroup
  • tst_QUndoStack
  • tst_qmake
  • tst_qmakelib
FALSEevaluated 41215 times by 34 tests
Evaluated by:
  • tst_Lancelot
  • tst_QApplication
  • tst_QCommandLineParser
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDir
  • tst_QFile
  • tst_QFont
  • tst_QLockFile
  • tst_QMimeDatabase
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QObject
  • tst_QProcess
  • tst_QProcess_and_GuiEventLoop
  • tst_QSharedMemory
  • tst_QSharedPointer
  • tst_QSystemSemaphore
  • tst_QTcpSocket
  • tst_QTextCodec
  • tst_QTextStream
  • ...
659-41215
98 return qt_safe_select(nfds, fdread, fdwrite, 0, 0);
executed 659 times by 6 tests: return qt_safe_select(nfds, fdread, fdwrite, 0, 0);
Executed by:
  • tst_QLockFile
  • tst_QProcess
  • tst_QUndoGroup
  • tst_QUndoStack
  • tst_qmake
  • tst_qmakelib
659
99-
100 struct timespec tv;-
101 tv.tv_sec = timeout / 1000;-
102 tv.tv_nsec = (timeout % 1000) * 1000 * 1000;-
103 return qt_safe_select(nfds, fdread, fdwrite, 0, &tv);
executed 41215 times by 34 tests: return qt_safe_select(nfds, fdread, fdwrite, 0, &tv);
Executed by:
  • tst_Lancelot
  • tst_QApplication
  • tst_QCommandLineParser
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDir
  • tst_QFile
  • tst_QFont
  • tst_QLockFile
  • tst_QMimeDatabase
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QObject
  • tst_QProcess
  • tst_QProcess_and_GuiEventLoop
  • tst_QSharedMemory
  • tst_QSharedPointer
  • tst_QSystemSemaphore
  • tst_QTcpSocket
  • tst_QTextCodec
  • tst_QTextStream
  • ...
41215
104}-
105-
106#ifdef Q_OS_BLACKBERRY-
107// The BlackBerry event dispatcher uses bps_get_event. Unfortunately, already registered-
108// socket notifiers are disabled by a call to select. This is to rearm the standard streams.-
109int bb_select(QList<QSocketNotifier *> socketNotifiers, int nfds, fd_set *fdread, fd_set *fdwrite,-
110 int timeout)-
111{-
112 QList<bool> socketNotifiersEnabled;-
113 socketNotifiersEnabled.reserve(socketNotifiers.count());-
114 for (int a = 0; a < socketNotifiers.count(); ++a) {-
115 if (socketNotifiers.at(a) && socketNotifiers.at(a)->isEnabled()) {-
116 socketNotifiersEnabled.append(true);-
117 socketNotifiers.at(a)->setEnabled(false);-
118 } else {-
119 socketNotifiersEnabled.append(false);-
120 }-
121 }-
122-
123 const int ret = qt_select_msecs(nfds, fdread, fdwrite, timeout);-
124-
125 for (int a = 0; a < socketNotifiers.count(); ++a) {-
126 if (socketNotifiersEnabled.at(a) == true)-
127 socketNotifiers.at(a)->setEnabled(true);-
128 }-
129-
130 return ret;-
131}-
132#endif // Q_OS_BLACKBERRY-
133-
134QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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