kernel/qcore_unix.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtCore module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
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 Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/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 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qcore_unix_p.h" -
43#include "qelapsedtimer.h" -
44 -
45#ifdef Q_OS_NACL -
46#elif !defined (Q_OS_VXWORKS) -
47# if !defined(Q_OS_HPUX) || defined(__ia64) -
48# include <sys/select.h> -
49# endif -
50# include <sys/time.h> -
51#else -
52# include <selectLib.h> -
53#endif -
54 -
55#include <stdlib.h> -
56 -
57#ifdef Q_OS_MAC -
58#include <mach/mach_time.h> -
59#endif -
60 -
61QT_BEGIN_NAMESPACE -
62 -
63static inline bool time_update(struct timeval *tv, const struct timeval &start, -
64 const struct timeval &timeout) -
65{ -
66 if (!QElapsedTimer::isMonotonic()) {
partially evaluated: !QElapsedTimer::isMonotonic()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:180
0-180
67 // we cannot recalculate the timeout without a monotonic clock as the time may have changed -
68 return false;
never executed: return false;
0
69 } -
70 -
71 // clock source is monotonic, so we can recalculate how much timeout is left -
72 struct timeval now = qt_gettime();
executed (the execution status of this line is deduced): struct timeval now = qt_gettime();
-
73 *tv = timeout + start - now;
executed (the execution status of this line is deduced): *tv = timeout + start - now;
-
74 return tv->tv_sec >= 0;
executed: return tv->tv_sec >= 0;
Execution Count:180
180
75} -
76 -
77int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept, -
78 const struct timeval *orig_timeout) -
79{ -
80 if (!orig_timeout) {
evaluated: !orig_timeout
TRUEFALSE
yes
Evaluation Count:11214
yes
Evaluation Count:60939
11214-60939
81 // no timeout -> block forever -
82 register int ret;
executed (the execution status of this line is deduced): register int ret;
-
83 EINTR_LOOP(ret, select(nfds, fdread, fdwrite, fdexcept, 0));
executed: }
Execution Count:11217
evaluated: ret == -1
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:11214
partially evaluated: (*__errno_location ()) == 4
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-11217
84 return ret;
executed: return ret;
Execution Count:11214
11214
85 } -
86 -
87 timeval start = qt_gettime();
executed (the execution status of this line is deduced): timeval start = qt_gettime();
-
88 timeval timeout = *orig_timeout;
executed (the execution status of this line is deduced): timeval timeout = *orig_timeout;
-
89 -
90 // loop and recalculate the timeout as needed -
91 int ret;
executed (the execution status of this line is deduced): int ret;
-
92 forever {
executed (the execution status of this line is deduced): for(;;) {
-
93 ret = ::select(nfds, fdread, fdwrite, fdexcept, &timeout);
executed (the execution status of this line is deduced): ret = ::select(nfds, fdread, fdwrite, fdexcept, &timeout);
-
94 if (ret != -1 || errno != EINTR)
evaluated: ret != -1
TRUEFALSE
yes
Evaluation Count:60942
yes
Evaluation Count:180
partially evaluated: (*__errno_location ()) != 4
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:180
0-60942
95 return ret;
executed: return ret;
Execution Count:60942
60942
96 -
97 // recalculate the timeout -
98 if (!time_update(&timeout, start, *orig_timeout)) {
partially evaluated: !time_update(&timeout, start, *orig_timeout)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:180
0-180
99 // timeout during update -
100 // or clock reset, fake timeout error -
101 return 0;
never executed: return 0;
0
102 } -
103 }
executed: }
Execution Count:180
180
104}
never executed: }
0
105 -
106QT_END_NAMESPACE -
107 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial