socket/qlocalsocket_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 QtNetwork 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 "qlocalsocket.h" -
43#include "qlocalsocket_p.h" -
44#include "qnet_unix_p.h" -
45 -
46#ifndef QT_NO_LOCALSOCKET -
47 -
48#include <sys/types.h> -
49#include <sys/socket.h> -
50#include <sys/un.h> -
51#include <unistd.h> -
52#include <fcntl.h> -
53#include <errno.h> -
54 -
55#include <qdir.h> -
56#include <qdebug.h> -
57#include <qelapsedtimer.h> -
58 -
59#ifdef Q_OS_VXWORKS -
60# include <selectLib.h> -
61#endif -
62 -
63#define QT_CONNECT_TIMEOUT 30000 -
64 -
65QT_BEGIN_NAMESPACE -
66 -
67QLocalSocketPrivate::QLocalSocketPrivate() : QIODevicePrivate(), -
68 delayConnect(0), -
69 connectTimer(0), -
70 connectingSocket(-1), -
71 connectingOpenMode(0), -
72 state(QLocalSocket::UnconnectedState) -
73{ -
74}
executed: }
Execution Count:156
156
75 -
76void QLocalSocketPrivate::init() -
77{ -
78 Q_Q(QLocalSocket);
executed (the execution status of this line is deduced): QLocalSocket * const q = q_func();
-
79 // QIODevice signals -
80 q->connect(&unixSocket, SIGNAL(aboutToClose()), q, SIGNAL(aboutToClose()));
executed (the execution status of this line is deduced): q->connect(&unixSocket, "2""aboutToClose()", q, "2""aboutToClose()");
-
81 q->connect(&unixSocket, SIGNAL(bytesWritten(qint64)),
executed (the execution status of this line is deduced): q->connect(&unixSocket, "2""bytesWritten(qint64)",
-
82 q, SIGNAL(bytesWritten(qint64)));
executed (the execution status of this line is deduced): q, "2""bytesWritten(qint64)");
-
83 q->connect(&unixSocket, SIGNAL(readyRead()), q, SIGNAL(readyRead()));
executed (the execution status of this line is deduced): q->connect(&unixSocket, "2""readyRead()", q, "2""readyRead()");
-
84 // QAbstractSocket signals -
85 q->connect(&unixSocket, SIGNAL(connected()), q, SIGNAL(connected()));
executed (the execution status of this line is deduced): q->connect(&unixSocket, "2""connected()", q, "2""connected()");
-
86 q->connect(&unixSocket, SIGNAL(disconnected()), q, SIGNAL(disconnected()));
executed (the execution status of this line is deduced): q->connect(&unixSocket, "2""disconnected()", q, "2""disconnected()");
-
87 q->connect(&unixSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
executed (the execution status of this line is deduced): q->connect(&unixSocket, "2""stateChanged(QAbstractSocket::SocketState)",
-
88 q, SLOT(_q_stateChanged(QAbstractSocket::SocketState)));
executed (the execution status of this line is deduced): q, "1""_q_stateChanged(QAbstractSocket::SocketState)");
-
89 q->connect(&unixSocket, SIGNAL(error(QAbstractSocket::SocketError)),
executed (the execution status of this line is deduced): q->connect(&unixSocket, "2""error(QAbstractSocket::SocketError)",
-
90 q, SLOT(_q_error(QAbstractSocket::SocketError)));
executed (the execution status of this line is deduced): q, "1""_q_error(QAbstractSocket::SocketError)");
-
91 q->connect(&unixSocket, SIGNAL(readChannelFinished()), q, SIGNAL(readChannelFinished()));
executed (the execution status of this line is deduced): q->connect(&unixSocket, "2""readChannelFinished()", q, "2""readChannelFinished()");
-
92 unixSocket.setParent(q);
executed (the execution status of this line is deduced): unixSocket.setParent(q);
-
93}
executed: }
Execution Count:157
157
94 -
95void QLocalSocketPrivate::_q_error(QAbstractSocket::SocketError socketError) -
96{ -
97 Q_Q(QLocalSocket);
executed (the execution status of this line is deduced): QLocalSocket * const q = q_func();
-
98 QString function = QLatin1String("QLocalSocket");
executed (the execution status of this line is deduced): QString function = QLatin1String("QLocalSocket");
-
99 QLocalSocket::LocalSocketError error = (QLocalSocket::LocalSocketError)socketError;
executed (the execution status of this line is deduced): QLocalSocket::LocalSocketError error = (QLocalSocket::LocalSocketError)socketError;
-
100 QString errorString = generateErrorString(error, function);
executed (the execution status of this line is deduced): QString errorString = generateErrorString(error, function);
-
101 q->setErrorString(errorString);
executed (the execution status of this line is deduced): q->setErrorString(errorString);
-
102 emit q->error(error);
executed (the execution status of this line is deduced): q->error(error);
-
103}
executed: }
Execution Count:21
21
104 -
105void QLocalSocketPrivate::_q_stateChanged(QAbstractSocket::SocketState newState) -
106{ -
107 Q_Q(QLocalSocket);
executed (the execution status of this line is deduced): QLocalSocket * const q = q_func();
-
108 QLocalSocket::LocalSocketState currentState = state;
executed (the execution status of this line is deduced): QLocalSocket::LocalSocketState currentState = state;
-
109 switch(newState) { -
110 case QAbstractSocket::UnconnectedState: -
111 state = QLocalSocket::UnconnectedState;
executed (the execution status of this line is deduced): state = QLocalSocket::UnconnectedState;
-
112 serverName.clear();
executed (the execution status of this line is deduced): serverName.clear();
-
113 fullServerName.clear();
executed (the execution status of this line is deduced): fullServerName.clear();
-
114 break;
executed: break;
Execution Count:143
143
115 case QAbstractSocket::ConnectingState: -
116 state = QLocalSocket::ConnectingState;
never executed (the execution status of this line is deduced): state = QLocalSocket::ConnectingState;
-
117 break;
never executed: break;
0
118 case QAbstractSocket::ConnectedState: -
119 state = QLocalSocket::ConnectedState;
executed (the execution status of this line is deduced): state = QLocalSocket::ConnectedState;
-
120 break;
executed: break;
Execution Count:146
146
121 case QAbstractSocket::ClosingState: -
122 state = QLocalSocket::ClosingState;
executed (the execution status of this line is deduced): state = QLocalSocket::ClosingState;
-
123 break;
executed: break;
Execution Count:146
146
124 default: -
125#if defined QLOCALSOCKET_DEBUG -
126 qWarning() << "QLocalSocket::Unhandled socket state change:" << newState; -
127#endif -
128 return;
never executed: return;
0
129 } -
130 if (currentState != state)
evaluated: currentState != state
TRUEFALSE
yes
Evaluation Count:364
yes
Evaluation Count:71
71-364
131 emit q->stateChanged(state);
executed: q->stateChanged(state);
Execution Count:364
364
132}
executed: }
Execution Count:435
435
133 -
134QString QLocalSocketPrivate::generateErrorString(QLocalSocket::LocalSocketError error, const QString &function) const -
135{ -
136 QString errorString;
executed (the execution status of this line is deduced): QString errorString;
-
137 switch (error) { -
138 case QLocalSocket::ConnectionRefusedError: -
139 errorString = QLocalSocket::tr("%1: Connection refused").arg(function);
never executed (the execution status of this line is deduced): errorString = QLocalSocket::tr("%1: Connection refused").arg(function);
-
140 break;
never executed: break;
0
141 case QLocalSocket::PeerClosedError: -
142 errorString = QLocalSocket::tr("%1: Remote closed").arg(function);
executed (the execution status of this line is deduced): errorString = QLocalSocket::tr("%1: Remote closed").arg(function);
-
143 break;
executed: break;
Execution Count:15
15
144 case QLocalSocket::ServerNotFoundError: -
145 errorString = QLocalSocket::tr("%1: Invalid name").arg(function);
executed (the execution status of this line is deduced): errorString = QLocalSocket::tr("%1: Invalid name").arg(function);
-
146 break;
executed: break;
Execution Count:10
10
147 case QLocalSocket::SocketAccessError: -
148 errorString = QLocalSocket::tr("%1: Socket access error").arg(function);
never executed (the execution status of this line is deduced): errorString = QLocalSocket::tr("%1: Socket access error").arg(function);
-
149 break;
never executed: break;
0
150 case QLocalSocket::SocketResourceError: -
151 errorString = QLocalSocket::tr("%1: Socket resource error").arg(function);
never executed (the execution status of this line is deduced): errorString = QLocalSocket::tr("%1: Socket resource error").arg(function);
-
152 break;
never executed: break;
0
153 case QLocalSocket::SocketTimeoutError: -
154 errorString = QLocalSocket::tr("%1: Socket operation timed out").arg(function);
executed (the execution status of this line is deduced): errorString = QLocalSocket::tr("%1: Socket operation timed out").arg(function);
-
155 break;
executed: break;
Execution Count:6
6
156 case QLocalSocket::DatagramTooLargeError: -
157 errorString = QLocalSocket::tr("%1: Datagram too large").arg(function);
never executed (the execution status of this line is deduced): errorString = QLocalSocket::tr("%1: Datagram too large").arg(function);
-
158 break;
never executed: break;
0
159 case QLocalSocket::ConnectionError: -
160 errorString = QLocalSocket::tr("%1: Connection error").arg(function);
never executed (the execution status of this line is deduced): errorString = QLocalSocket::tr("%1: Connection error").arg(function);
-
161 break;
never executed: break;
0
162 case QLocalSocket::UnsupportedSocketOperationError: -
163 errorString = QLocalSocket::tr("%1: The socket operation is not supported").arg(function);
never executed (the execution status of this line is deduced): errorString = QLocalSocket::tr("%1: The socket operation is not supported").arg(function);
-
164 break;
never executed: break;
0
165 case QLocalSocket::OperationError: -
166 errorString = QLocalSocket::tr("%1: Operation not permitted when socket is in this state").arg(function);
never executed (the execution status of this line is deduced): errorString = QLocalSocket::tr("%1: Operation not permitted when socket is in this state").arg(function);
-
167 break;
never executed: break;
0
168 case QLocalSocket::UnknownSocketError: -
169 default: -
170 errorString = QLocalSocket::tr("%1: Unknown error %2").arg(function).arg(errno);
never executed (the execution status of this line is deduced): errorString = QLocalSocket::tr("%1: Unknown error %2").arg(function).arg((*__errno_location ()));
-
171 }
never executed: }
0
172 return errorString;
executed: return errorString;
Execution Count:31
31
173} -
174 -
175void QLocalSocketPrivate::errorOccurred(QLocalSocket::LocalSocketError error, const QString &function) -
176{ -
177 Q_Q(QLocalSocket);
executed (the execution status of this line is deduced): QLocalSocket * const q = q_func();
-
178 switch (error) { -
179 case QLocalSocket::ConnectionRefusedError: -
180 unixSocket.setSocketError(QAbstractSocket::ConnectionRefusedError);
never executed (the execution status of this line is deduced): unixSocket.setSocketError(QAbstractSocket::ConnectionRefusedError);
-
181 break;
never executed: break;
0
182 case QLocalSocket::PeerClosedError: -
183 unixSocket.setSocketError(QAbstractSocket::RemoteHostClosedError);
never executed (the execution status of this line is deduced): unixSocket.setSocketError(QAbstractSocket::RemoteHostClosedError);
-
184 break;
never executed: break;
0
185 case QLocalSocket::ServerNotFoundError: -
186 unixSocket.setSocketError(QAbstractSocket::HostNotFoundError);
executed (the execution status of this line is deduced): unixSocket.setSocketError(QAbstractSocket::HostNotFoundError);
-
187 break;
executed: break;
Execution Count:10
10
188 case QLocalSocket::SocketAccessError: -
189 unixSocket.setSocketError(QAbstractSocket::SocketAccessError);
never executed (the execution status of this line is deduced): unixSocket.setSocketError(QAbstractSocket::SocketAccessError);
-
190 break;
never executed: break;
0
191 case QLocalSocket::SocketResourceError: -
192 unixSocket.setSocketError(QAbstractSocket::SocketResourceError);
never executed (the execution status of this line is deduced): unixSocket.setSocketError(QAbstractSocket::SocketResourceError);
-
193 break;
never executed: break;
0
194 case QLocalSocket::SocketTimeoutError: -
195 unixSocket.setSocketError(QAbstractSocket::SocketTimeoutError);
never executed (the execution status of this line is deduced): unixSocket.setSocketError(QAbstractSocket::SocketTimeoutError);
-
196 break;
never executed: break;
0
197 case QLocalSocket::DatagramTooLargeError: -
198 unixSocket.setSocketError(QAbstractSocket::DatagramTooLargeError);
never executed (the execution status of this line is deduced): unixSocket.setSocketError(QAbstractSocket::DatagramTooLargeError);
-
199 break;
never executed: break;
0
200 case QLocalSocket::ConnectionError: -
201 unixSocket.setSocketError(QAbstractSocket::NetworkError);
never executed (the execution status of this line is deduced): unixSocket.setSocketError(QAbstractSocket::NetworkError);
-
202 break;
never executed: break;
0
203 case QLocalSocket::UnsupportedSocketOperationError: -
204 unixSocket.setSocketError(QAbstractSocket::UnsupportedSocketOperationError);
never executed (the execution status of this line is deduced): unixSocket.setSocketError(QAbstractSocket::UnsupportedSocketOperationError);
-
205 break;
never executed: break;
0
206 case QLocalSocket::UnknownSocketError: -
207 default: -
208 unixSocket.setSocketError(QAbstractSocket::UnknownSocketError);
never executed (the execution status of this line is deduced): unixSocket.setSocketError(QAbstractSocket::UnknownSocketError);
-
209 }
never executed: }
0
210 -
211 QString errorString = generateErrorString(error, function);
executed (the execution status of this line is deduced): QString errorString = generateErrorString(error, function);
-
212 q->setErrorString(errorString);
executed (the execution status of this line is deduced): q->setErrorString(errorString);
-
213 emit q->error(error);
executed (the execution status of this line is deduced): q->error(error);
-
214 -
215 // errors cause a disconnect -
216 unixSocket.setSocketState(QAbstractSocket::UnconnectedState);
executed (the execution status of this line is deduced): unixSocket.setSocketState(QAbstractSocket::UnconnectedState);
-
217 bool stateChanged = (state != QLocalSocket::UnconnectedState);
executed (the execution status of this line is deduced): bool stateChanged = (state != QLocalSocket::UnconnectedState);
-
218 state = QLocalSocket::UnconnectedState;
executed (the execution status of this line is deduced): state = QLocalSocket::UnconnectedState;
-
219 q->close();
executed (the execution status of this line is deduced): q->close();
-
220 if (stateChanged)
partially evaluated: stateChanged
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
0-10
221 q->emit stateChanged(state);
executed: q-> stateChanged(state);
Execution Count:10
10
222}
executed: }
Execution Count:10
10
223 -
224void QLocalSocket::connectToServer(const QString &name, OpenMode openMode) -
225{ -
226 Q_D(QLocalSocket);
executed (the execution status of this line is deduced): QLocalSocketPrivate * const d = d_func();
-
227 if (state() == ConnectedState || state() == ConnectingState) {
partially evaluated: state() == ConnectedState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:85
partially evaluated: state() == ConnectingState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:85
0-85
228 QString errorString = d->generateErrorString(QLocalSocket::OperationError, QLatin1String("QLocalSocket::connectToserver"));
never executed (the execution status of this line is deduced): QString errorString = d->generateErrorString(QLocalSocket::OperationError, QLatin1String("QLocalSocket::connectToserver"));
-
229 setErrorString(errorString);
never executed (the execution status of this line is deduced): setErrorString(errorString);
-
230 emit error(QLocalSocket::OperationError);
never executed (the execution status of this line is deduced): error(QLocalSocket::OperationError);
-
231 return;
never executed: return;
0
232 } -
233 -
234 d->errorString.clear();
executed (the execution status of this line is deduced): d->errorString.clear();
-
235 d->unixSocket.setSocketState(QAbstractSocket::ConnectingState);
executed (the execution status of this line is deduced): d->unixSocket.setSocketState(QAbstractSocket::ConnectingState);
-
236 d->state = ConnectingState;
executed (the execution status of this line is deduced): d->state = ConnectingState;
-
237 emit stateChanged(d->state);
executed (the execution status of this line is deduced): stateChanged(d->state);
-
238 -
239 if (name.isEmpty()) {
evaluated: name.isEmpty()
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:76
9-76
240 d->errorOccurred(ServerNotFoundError,
executed (the execution status of this line is deduced): d->errorOccurred(ServerNotFoundError,
-
241 QLatin1String("QLocalSocket::connectToServer"));
executed (the execution status of this line is deduced): QLatin1String("QLocalSocket::connectToServer"));
-
242 return;
executed: return;
Execution Count:9
9
243 } -
244 -
245 // create the socket -
246 if (-1 == (d->connectingSocket = qt_safe_socket(PF_UNIX, SOCK_STREAM, 0))) {
partially evaluated: -1 == (d->connectingSocket = qt_safe_socket(1, SOCK_STREAM, 0))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:76
0-76
247 d->errorOccurred(UnsupportedSocketOperationError,
never executed (the execution status of this line is deduced): d->errorOccurred(UnsupportedSocketOperationError,
-
248 QLatin1String("QLocalSocket::connectToServer"));
never executed (the execution status of this line is deduced): QLatin1String("QLocalSocket::connectToServer"));
-
249 return;
never executed: return;
0
250 } -
251 // set non blocking so we can try to connect and it won't wait -
252 int flags = fcntl(d->connectingSocket, F_GETFL, 0);
executed (the execution status of this line is deduced): int flags = fcntl(d->connectingSocket, 3, 0);
-
253 if (-1 == flags
partially evaluated: -1 == flags
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:76
0-76
254 || -1 == (fcntl(d->connectingSocket, F_SETFL, flags | O_NONBLOCK))) {
partially evaluated: -1 == (fcntl(d->connectingSocket, 4, flags | 04000))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:76
0-76
255 d->errorOccurred(UnknownSocketError,
never executed (the execution status of this line is deduced): d->errorOccurred(UnknownSocketError,
-
256 QLatin1String("QLocalSocket::connectToServer"));
never executed (the execution status of this line is deduced): QLatin1String("QLocalSocket::connectToServer"));
-
257 return;
never executed: return;
0
258 } -
259 -
260 // _q_connectToSocket does the actual connecting -
261 d->connectingName = name;
executed (the execution status of this line is deduced): d->connectingName = name;
-
262 d->connectingOpenMode = openMode;
executed (the execution status of this line is deduced): d->connectingOpenMode = openMode;
-
263 d->_q_connectToSocket();
executed (the execution status of this line is deduced): d->_q_connectToSocket();
-
264}
executed: }
Execution Count:76
76
265 -
266/*! -
267 \internal -
268 -
269 Tries to connect connectingName and connectingOpenMode -
270 -
271 \sa connectToServer(), waitForConnected() -
272 */ -
273void QLocalSocketPrivate::_q_connectToSocket() -
274{ -
275 Q_Q(QLocalSocket);
executed (the execution status of this line is deduced): QLocalSocket * const q = q_func();
-
276 QString connectingPathName;
executed (the execution status of this line is deduced): QString connectingPathName;
-
277 -
278 // determine the full server path -
279 if (connectingName.startsWith(QLatin1Char('/'))) {
evaluated: connectingName.startsWith(QLatin1Char('/'))
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:75
1-75
280 connectingPathName = connectingName;
executed (the execution status of this line is deduced): connectingPathName = connectingName;
-
281 } else {
executed: }
Execution Count:1
1
282 connectingPathName = QDir::tempPath();
executed (the execution status of this line is deduced): connectingPathName = QDir::tempPath();
-
283 connectingPathName += QLatin1Char('/') + connectingName;
executed (the execution status of this line is deduced): connectingPathName += QLatin1Char('/') + connectingName;
-
284 }
executed: }
Execution Count:75
75
285 -
286 struct sockaddr_un name;
executed (the execution status of this line is deduced): struct sockaddr_un name;
-
287 name.sun_family = PF_UNIX;
executed (the execution status of this line is deduced): name.sun_family = 1;
-
288 if (sizeof(name.sun_path) < (uint)connectingPathName.toLatin1().size() + 1) {
evaluated: sizeof(name.sun_path) < (uint)connectingPathName.toLatin1().size() + 1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:75
1-75
289 QString function = QLatin1String("QLocalSocket::connectToServer");
executed (the execution status of this line is deduced): QString function = QLatin1String("QLocalSocket::connectToServer");
-
290 errorOccurred(QLocalSocket::ServerNotFoundError, function);
executed (the execution status of this line is deduced): errorOccurred(QLocalSocket::ServerNotFoundError, function);
-
291 return;
executed: return;
Execution Count:1
1
292 } -
293 ::memcpy(name.sun_path, connectingPathName.toLatin1().data(),
executed (the execution status of this line is deduced): ::memcpy(name.sun_path, connectingPathName.toLatin1().data(),
-
294 connectingPathName.toLatin1().size() + 1);
executed (the execution status of this line is deduced): connectingPathName.toLatin1().size() + 1);
-
295 if (-1 == qt_safe_connect(connectingSocket, (struct sockaddr *)&name, sizeof(name))) {
partially evaluated: -1 == qt_safe_connect(connectingSocket, (struct sockaddr *)&name, sizeof(name))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:75
0-75
296 QString function = QLatin1String("QLocalSocket::connectToServer");
never executed (the execution status of this line is deduced): QString function = QLatin1String("QLocalSocket::connectToServer");
-
297 switch (errno) -
298 { -
299 case EINVAL: -
300 case ECONNREFUSED: -
301 errorOccurred(QLocalSocket::ConnectionRefusedError, function);
never executed (the execution status of this line is deduced): errorOccurred(QLocalSocket::ConnectionRefusedError, function);
-
302 break;
never executed: break;
0
303 case ENOENT: -
304 errorOccurred(QLocalSocket::ServerNotFoundError, function);
never executed (the execution status of this line is deduced): errorOccurred(QLocalSocket::ServerNotFoundError, function);
-
305 break;
never executed: break;
0
306 case EACCES: -
307 case EPERM: -
308 errorOccurred(QLocalSocket::SocketAccessError, function);
never executed (the execution status of this line is deduced): errorOccurred(QLocalSocket::SocketAccessError, function);
-
309 break;
never executed: break;
0
310 case ETIMEDOUT: -
311 errorOccurred(QLocalSocket::SocketTimeoutError, function);
never executed (the execution status of this line is deduced): errorOccurred(QLocalSocket::SocketTimeoutError, function);
-
312 break;
never executed: break;
0
313 case EAGAIN: -
314 // Try again later, all of the sockets listening are full -
315 if (!delayConnect) {
never evaluated: !delayConnect
0
316 delayConnect = new QSocketNotifier(connectingSocket, QSocketNotifier::Write, q);
never executed (the execution status of this line is deduced): delayConnect = new QSocketNotifier(connectingSocket, QSocketNotifier::Write, q);
-
317 q->connect(delayConnect, SIGNAL(activated(int)), q, SLOT(_q_connectToSocket()));
never executed (the execution status of this line is deduced): q->connect(delayConnect, "2""activated(int)", q, "1""_q_connectToSocket()");
-
318 }
never executed: }
0
319 if (!connectTimer) {
never evaluated: !connectTimer
0
320 connectTimer = new QTimer(q);
never executed (the execution status of this line is deduced): connectTimer = new QTimer(q);
-
321 q->connect(connectTimer, SIGNAL(timeout()),
never executed (the execution status of this line is deduced): q->connect(connectTimer, "2""timeout()",
-
322 q, SLOT(_q_abortConnectionAttempt()),
never executed (the execution status of this line is deduced): q, "1""_q_abortConnectionAttempt()",
-
323 Qt::DirectConnection);
never executed (the execution status of this line is deduced): Qt::DirectConnection);
-
324 connectTimer->start(QT_CONNECT_TIMEOUT);
never executed (the execution status of this line is deduced): connectTimer->start(30000);
-
325 }
never executed: }
0
326 delayConnect->setEnabled(true);
never executed (the execution status of this line is deduced): delayConnect->setEnabled(true);
-
327 break;
never executed: break;
0
328 default: -
329 errorOccurred(QLocalSocket::UnknownSocketError, function);
never executed (the execution status of this line is deduced): errorOccurred(QLocalSocket::UnknownSocketError, function);
-
330 }
never executed: }
0
331 return;
never executed: return;
0
332 } -
333 -
334 // connected! -
335 cancelDelayedConnect();
executed (the execution status of this line is deduced): cancelDelayedConnect();
-
336 -
337 serverName = connectingName;
executed (the execution status of this line is deduced): serverName = connectingName;
-
338 fullServerName = connectingPathName;
executed (the execution status of this line is deduced): fullServerName = connectingPathName;
-
339 if (unixSocket.setSocketDescriptor(connectingSocket,
partially evaluated: unixSocket.setSocketDescriptor(connectingSocket, QAbstractSocket::ConnectedState, connectingOpenMode)
TRUEFALSE
yes
Evaluation Count:75
no
Evaluation Count:0
0-75
340 QAbstractSocket::ConnectedState, connectingOpenMode)) {
partially evaluated: unixSocket.setSocketDescriptor(connectingSocket, QAbstractSocket::ConnectedState, connectingOpenMode)
TRUEFALSE
yes
Evaluation Count:75
no
Evaluation Count:0
0-75
341 q->QIODevice::open(connectingOpenMode | QIODevice::Unbuffered);
executed (the execution status of this line is deduced): q->QIODevice::open(connectingOpenMode | QIODevice::Unbuffered);
-
342 q->emit connected();
executed (the execution status of this line is deduced): q-> connected();
-
343 } else {
executed: }
Execution Count:75
75
344 QString function = QLatin1String("QLocalSocket::connectToServer");
never executed (the execution status of this line is deduced): QString function = QLatin1String("QLocalSocket::connectToServer");
-
345 errorOccurred(QLocalSocket::UnknownSocketError, function);
never executed (the execution status of this line is deduced): errorOccurred(QLocalSocket::UnknownSocketError, function);
-
346 }
never executed: }
0
347 connectingSocket = -1;
executed (the execution status of this line is deduced): connectingSocket = -1;
-
348 connectingName.clear();
executed (the execution status of this line is deduced): connectingName.clear();
-
349 connectingOpenMode = 0;
executed (the execution status of this line is deduced): connectingOpenMode = 0;
-
350}
executed: }
Execution Count:75
75
351 -
352bool QLocalSocket::setSocketDescriptor(qintptr socketDescriptor, -
353 LocalSocketState socketState, OpenMode openMode) -
354{ -
355 Q_D(QLocalSocket);
executed (the execution status of this line is deduced): QLocalSocketPrivate * const d = d_func();
-
356 QAbstractSocket::SocketState newSocketState = QAbstractSocket::UnconnectedState;
executed (the execution status of this line is deduced): QAbstractSocket::SocketState newSocketState = QAbstractSocket::UnconnectedState;
-
357 switch (socketState) { -
358 case ConnectingState: -
359 newSocketState = QAbstractSocket::ConnectingState;
executed (the execution status of this line is deduced): newSocketState = QAbstractSocket::ConnectingState;
-
360 break;
executed: break;
Execution Count:1
1
361 case ConnectedState: -
362 newSocketState = QAbstractSocket::ConnectedState;
executed (the execution status of this line is deduced): newSocketState = QAbstractSocket::ConnectedState;
-
363 break;
executed: break;
Execution Count:71
71
364 case ClosingState: -
365 newSocketState = QAbstractSocket::ClosingState;
never executed (the execution status of this line is deduced): newSocketState = QAbstractSocket::ClosingState;
-
366 break;
never executed: break;
0
367 case UnconnectedState: -
368 newSocketState = QAbstractSocket::UnconnectedState;
never executed (the execution status of this line is deduced): newSocketState = QAbstractSocket::UnconnectedState;
-
369 break;
never executed: break;
0
370 } -
371 QIODevice::open(openMode);
executed (the execution status of this line is deduced): QIODevice::open(openMode);
-
372 d->state = socketState;
executed (the execution status of this line is deduced): d->state = socketState;
-
373 return d->unixSocket.setSocketDescriptor(socketDescriptor,
executed: return d->unixSocket.setSocketDescriptor(socketDescriptor, newSocketState, openMode);
Execution Count:72
72
374 newSocketState, openMode);
executed: return d->unixSocket.setSocketDescriptor(socketDescriptor, newSocketState, openMode);
Execution Count:72
72
375} -
376 -
377void QLocalSocketPrivate::_q_abortConnectionAttempt() -
378{ -
379 Q_Q(QLocalSocket);
never executed (the execution status of this line is deduced): QLocalSocket * const q = q_func();
-
380 q->close();
never executed (the execution status of this line is deduced): q->close();
-
381}
never executed: }
0
382 -
383void QLocalSocketPrivate::cancelDelayedConnect() -
384{ -
385 if (delayConnect) {
partially evaluated: delayConnect
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:290
0-290
386 delayConnect->setEnabled(false);
never executed (the execution status of this line is deduced): delayConnect->setEnabled(false);
-
387 delete delayConnect;
never executed (the execution status of this line is deduced): delete delayConnect;
-
388 delayConnect = 0;
never executed (the execution status of this line is deduced): delayConnect = 0;
-
389 connectTimer->stop();
never executed (the execution status of this line is deduced): connectTimer->stop();
-
390 delete connectTimer;
never executed (the execution status of this line is deduced): delete connectTimer;
-
391 connectTimer = 0;
never executed (the execution status of this line is deduced): connectTimer = 0;
-
392 }
never executed: }
0
393}
executed: }
Execution Count:290
290
394 -
395qintptr QLocalSocket::socketDescriptor() const -
396{ -
397 Q_D(const QLocalSocket);
executed (the execution status of this line is deduced): const QLocalSocketPrivate * const d = d_func();
-
398 return d->unixSocket.socketDescriptor();
executed: return d->unixSocket.socketDescriptor();
Execution Count:1
1
399} -
400 -
401qint64 QLocalSocket::readData(char *data, qint64 c) -
402{ -
403 Q_D(QLocalSocket);
executed (the execution status of this line is deduced): QLocalSocketPrivate * const d = d_func();
-
404 return d->unixSocket.read(data, c);
executed: return d->unixSocket.read(data, c);
Execution Count:469
469
405} -
406 -
407qint64 QLocalSocket::writeData(const char *data, qint64 c) -
408{ -
409 Q_D(QLocalSocket);
executed (the execution status of this line is deduced): QLocalSocketPrivate * const d = d_func();
-
410 return d->unixSocket.writeData(data, c);
executed: return d->unixSocket.writeData(data, c);
Execution Count:54
54
411} -
412 -
413void QLocalSocket::abort() -
414{ -
415 Q_D(QLocalSocket);
executed (the execution status of this line is deduced): QLocalSocketPrivate * const d = d_func();
-
416 d->unixSocket.abort();
executed (the execution status of this line is deduced): d->unixSocket.abort();
-
417}
executed: }
Execution Count:1
1
418 -
419qint64 QLocalSocket::bytesAvailable() const -
420{ -
421 Q_D(const QLocalSocket);
executed (the execution status of this line is deduced): const QLocalSocketPrivate * const d = d_func();
-
422 return QIODevice::bytesAvailable() + d->unixSocket.bytesAvailable();
executed: return QIODevice::bytesAvailable() + d->unixSocket.bytesAvailable();
Execution Count:97
97
423} -
424 -
425qint64 QLocalSocket::bytesToWrite() const -
426{ -
427 Q_D(const QLocalSocket);
executed (the execution status of this line is deduced): const QLocalSocketPrivate * const d = d_func();
-
428 return d->unixSocket.bytesToWrite();
executed: return d->unixSocket.bytesToWrite();
Execution Count:16
16
429} -
430 -
431bool QLocalSocket::canReadLine() const -
432{ -
433 Q_D(const QLocalSocket);
executed (the execution status of this line is deduced): const QLocalSocketPrivate * const d = d_func();
-
434 return QIODevice::canReadLine() || d->unixSocket.canReadLine();
executed: return QIODevice::canReadLine() || d->unixSocket.canReadLine();
Execution Count:16
16
435} -
436 -
437void QLocalSocket::close() -
438{ -
439 Q_D(QLocalSocket);
executed (the execution status of this line is deduced): QLocalSocketPrivate * const d = d_func();
-
440 d->unixSocket.close();
executed (the execution status of this line is deduced): d->unixSocket.close();
-
441 d->cancelDelayedConnect();
executed (the execution status of this line is deduced): d->cancelDelayedConnect();
-
442 if (d->connectingSocket != -1)
evaluated: d->connectingSocket != -1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:214
1-214
443 ::close(d->connectingSocket);
executed: ::close(d->connectingSocket);
Execution Count:1
1
444 d->connectingSocket = -1;
executed (the execution status of this line is deduced): d->connectingSocket = -1;
-
445 d->connectingName.clear();
executed (the execution status of this line is deduced): d->connectingName.clear();
-
446 d->connectingOpenMode = 0;
executed (the execution status of this line is deduced): d->connectingOpenMode = 0;
-
447 d->serverName.clear();
executed (the execution status of this line is deduced): d->serverName.clear();
-
448 d->fullServerName.clear();
executed (the execution status of this line is deduced): d->fullServerName.clear();
-
449 QIODevice::close();
executed (the execution status of this line is deduced): QIODevice::close();
-
450}
executed: }
Execution Count:215
215
451 -
452bool QLocalSocket::waitForBytesWritten(int msecs) -
453{ -
454 Q_D(QLocalSocket);
executed (the execution status of this line is deduced): QLocalSocketPrivate * const d = d_func();
-
455 return d->unixSocket.waitForBytesWritten(msecs);
executed: return d->unixSocket.waitForBytesWritten(msecs);
Execution Count:43
43
456} -
457 -
458bool QLocalSocket::flush() -
459{ -
460 Q_D(QLocalSocket);
executed (the execution status of this line is deduced): QLocalSocketPrivate * const d = d_func();
-
461 return d->unixSocket.flush();
executed: return d->unixSocket.flush();
Execution Count:16
16
462} -
463 -
464void QLocalSocket::disconnectFromServer() -
465{ -
466 Q_D(QLocalSocket);
executed (the execution status of this line is deduced): QLocalSocketPrivate * const d = d_func();
-
467 d->unixSocket.disconnectFromHost();
executed (the execution status of this line is deduced): d->unixSocket.disconnectFromHost();
-
468}
executed: }
Execution Count:10
10
469 -
470QLocalSocket::LocalSocketError QLocalSocket::error() const -
471{ -
472 Q_D(const QLocalSocket);
executed (the execution status of this line is deduced): const QLocalSocketPrivate * const d = d_func();
-
473 switch (d->unixSocket.error()) { -
474 case QAbstractSocket::ConnectionRefusedError: -
475 return QLocalSocket::ConnectionRefusedError;
never executed: return QLocalSocket::ConnectionRefusedError;
0
476 case QAbstractSocket::RemoteHostClosedError: -
477 return QLocalSocket::PeerClosedError;
executed: return QLocalSocket::PeerClosedError;
Execution Count:1
1
478 case QAbstractSocket::HostNotFoundError: -
479 return QLocalSocket::ServerNotFoundError;
executed: return QLocalSocket::ServerNotFoundError;
Execution Count:16
16
480 case QAbstractSocket::SocketAccessError: -
481 return QLocalSocket::SocketAccessError;
never executed: return QLocalSocket::SocketAccessError;
0
482 case QAbstractSocket::SocketResourceError: -
483 return QLocalSocket::SocketResourceError;
never executed: return QLocalSocket::SocketResourceError;
0
484 case QAbstractSocket::SocketTimeoutError: -
485 return QLocalSocket::SocketTimeoutError;
executed: return QLocalSocket::SocketTimeoutError;
Execution Count:6
6
486 case QAbstractSocket::DatagramTooLargeError: -
487 return QLocalSocket::DatagramTooLargeError;
never executed: return QLocalSocket::DatagramTooLargeError;
0
488 case QAbstractSocket::NetworkError: -
489 return QLocalSocket::ConnectionError;
never executed: return QLocalSocket::ConnectionError;
0
490 case QAbstractSocket::UnsupportedSocketOperationError: -
491 return QLocalSocket::UnsupportedSocketOperationError;
never executed: return QLocalSocket::UnsupportedSocketOperationError;
0
492 case QAbstractSocket::UnknownSocketError: -
493 return QLocalSocket::UnknownSocketError;
executed: return QLocalSocket::UnknownSocketError;
Execution Count:7
7
494 default: -
495#if defined QLOCALSOCKET_DEBUG -
496 qWarning() << "QLocalSocket error not handled:" << d->unixSocket.error(); -
497#endif -
498 break;
never executed: break;
0
499 } -
500 return UnknownSocketError;
never executed: return UnknownSocketError;
0
501} -
502 -
503bool QLocalSocket::isValid() const -
504{ -
505 Q_D(const QLocalSocket);
executed (the execution status of this line is deduced): const QLocalSocketPrivate * const d = d_func();
-
506 return d->unixSocket.isValid();
executed: return d->unixSocket.isValid();
Execution Count:22
22
507} -
508 -
509qint64 QLocalSocket::readBufferSize() const -
510{ -
511 Q_D(const QLocalSocket);
executed (the execution status of this line is deduced): const QLocalSocketPrivate * const d = d_func();
-
512 return d->unixSocket.readBufferSize();
executed: return d->unixSocket.readBufferSize();
Execution Count:16
16
513} -
514 -
515void QLocalSocket::setReadBufferSize(qint64 size) -
516{ -
517 Q_D(QLocalSocket);
executed (the execution status of this line is deduced): QLocalSocketPrivate * const d = d_func();
-
518 d->unixSocket.setReadBufferSize(size);
executed (the execution status of this line is deduced): d->unixSocket.setReadBufferSize(size);
-
519}
executed: }
Execution Count:2
2
520 -
521bool QLocalSocket::waitForConnected(int msec) -
522{ -
523 Q_D(QLocalSocket);
executed (the execution status of this line is deduced): QLocalSocketPrivate * const d = d_func();
-
524 if (state() != ConnectingState)
partially evaluated: state() != ConnectingState
TRUEFALSE
yes
Evaluation Count:74
no
Evaluation Count:0
0-74
525 return (state() == ConnectedState);
executed: return (state() == ConnectedState);
Execution Count:74
74
526 -
527 fd_set fds;
never executed (the execution status of this line is deduced): fd_set fds;
-
528 FD_ZERO(&fds);
never executed: }
never evaluated: 0
0
529 FD_SET(d->connectingSocket, &fds);
never executed (the execution status of this line is deduced): (((&fds)->fds_bits)[((d->connectingSocket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) 1 << ((d->connectingSocket) % (8 * (int) sizeof (__fd_mask)))));
-
530 -
531 timeval timeout;
never executed (the execution status of this line is deduced): timeval timeout;
-
532 timeout.tv_sec = msec / 1000;
never executed (the execution status of this line is deduced): timeout.tv_sec = msec / 1000;
-
533 timeout.tv_usec = (msec % 1000) * 1000;
never executed (the execution status of this line is deduced): timeout.tv_usec = (msec % 1000) * 1000;
-
534 -
535 // timeout can not be 0 or else select will return an error. -
536 if (0 == msec)
never evaluated: 0 == msec
0
537 timeout.tv_usec = 1000;
never executed: timeout.tv_usec = 1000;
0
538 -
539 int result = -1;
never executed (the execution status of this line is deduced): int result = -1;
-
540 // on Linux timeout will be updated by select, but _not_ on other systems. -
541 QElapsedTimer timer;
never executed (the execution status of this line is deduced): QElapsedTimer timer;
-
542 timer.start();
never executed (the execution status of this line is deduced): timer.start();
-
543 while (state() == ConnectingState
never evaluated: state() == ConnectingState
0
544 && (-1 == msec || timer.elapsed() < msec)) {
never evaluated: -1 == msec
never evaluated: timer.elapsed() < msec
0
545 result = ::select(d->connectingSocket + 1, &fds, 0, 0, &timeout);
never executed (the execution status of this line is deduced): result = ::select(d->connectingSocket + 1, &fds, 0, 0, &timeout);
-
546 if (-1 == result && errno != EINTR) {
never evaluated: -1 == result
never evaluated: (*__errno_location ()) != 4
0
547 d->errorOccurred( QLocalSocket::UnknownSocketError,
never executed (the execution status of this line is deduced): d->errorOccurred( QLocalSocket::UnknownSocketError,
-
548 QLatin1String("QLocalSocket::waitForConnected"));
never executed (the execution status of this line is deduced): QLatin1String("QLocalSocket::waitForConnected"));
-
549 break;
never executed: break;
0
550 } -
551 if (result > 0)
never evaluated: result > 0
0
552 d->_q_connectToSocket();
never executed: d->_q_connectToSocket();
0
553 }
never executed: }
0
554 -
555 return (state() == ConnectedState);
never executed: return (state() == ConnectedState);
0
556} -
557 -
558bool QLocalSocket::waitForDisconnected(int msecs) -
559{ -
560 Q_D(QLocalSocket);
executed (the execution status of this line is deduced): QLocalSocketPrivate * const d = d_func();
-
561 if (state() == UnconnectedState) {
evaluated: state() == UnconnectedState
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
562 qWarning() << "QLocalSocket::waitForDisconnected() is not allowed in UnconnectedState";
executed (the execution status of this line is deduced): QMessageLogger("socket/qlocalsocket_unix.cpp", 562, __PRETTY_FUNCTION__).warning() << "QLocalSocket::waitForDisconnected() is not allowed in UnconnectedState";
-
563 return false;
executed: return false;
Execution Count:2
2
564 } -
565 return (d->unixSocket.waitForDisconnected(msecs));
executed: return (d->unixSocket.waitForDisconnected(msecs));
Execution Count:2
2
566} -
567 -
568bool QLocalSocket::waitForReadyRead(int msecs) -
569{ -
570 Q_D(QLocalSocket);
executed (the execution status of this line is deduced): QLocalSocketPrivate * const d = d_func();
-
571 if (state() == QLocalSocket::UnconnectedState)
evaluated: state() == QLocalSocket::UnconnectedState
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:51
7-51
572 return false;
executed: return false;
Execution Count:7
7
573 return (d->unixSocket.waitForReadyRead(msecs));
executed: return (d->unixSocket.waitForReadyRead(msecs));
Execution Count:51
51
574} -
575 -
576QT_END_NAMESPACE -
577 -
578#endif -
579 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial