socket/qabstractsocket.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//#define QABSTRACTSOCKET_DEBUG -
43 -
44/*! -
45 \class QAbstractSocket -
46 -
47 \brief The QAbstractSocket class provides the base functionality -
48 common to all socket types. -
49 -
50 \reentrant -
51 \ingroup network -
52 \inmodule QtNetwork -
53 -
54 QAbstractSocket is the base class for QTcpSocket and QUdpSocket -
55 and contains all common functionality of these two classes. If -
56 you need a socket, you have two options: -
57 -
58 \list -
59 \li Instantiate QTcpSocket or QUdpSocket. -
60 \li Create a native socket descriptor, instantiate -
61 QAbstractSocket, and call setSocketDescriptor() to wrap the -
62 native socket. -
63 \endlist -
64 -
65 TCP (Transmission Control Protocol) is a reliable, -
66 stream-oriented, connection-oriented transport protocol. UDP -
67 (User Datagram Protocol) is an unreliable, datagram-oriented, -
68 connectionless protocol. In practice, this means that TCP is -
69 better suited for continuous transmission of data, whereas the -
70 more lightweight UDP can be used when reliability isn't -
71 important. -
72 -
73 QAbstractSocket's API unifies most of the differences between the -
74 two protocols. For example, although UDP is connectionless, -
75 connectToHost() establishes a virtual connection for UDP sockets, -
76 enabling you to use QAbstractSocket in more or less the same way -
77 regardless of the underlying protocol. Internally, -
78 QAbstractSocket remembers the address and port passed to -
79 connectToHost(), and functions like read() and write() use these -
80 values. -
81 -
82 At any time, QAbstractSocket has a state (returned by -
83 state()). The initial state is UnconnectedState. After -
84 calling connectToHost(), the socket first enters -
85 HostLookupState. If the host is found, QAbstractSocket enters -
86 ConnectingState and emits the hostFound() signal. When the -
87 connection has been established, it enters ConnectedState and -
88 emits connected(). If an error occurs at any stage, error() is -
89 emitted. Whenever the state changes, stateChanged() is emitted. -
90 For convenience, isValid() returns true if the socket is ready for -
91 reading and writing, but note that the socket's state must be -
92 ConnectedState before reading and writing can occur. -
93 -
94 Read or write data by calling read() or write(), or use the -
95 convenience functions readLine() and readAll(). QAbstractSocket -
96 also inherits getChar(), putChar(), and ungetChar() from -
97 QIODevice, which work on single bytes. The bytesWritten() signal -
98 is emitted when data has been written to the socket. Note that Qt does -
99 not limit the write buffer size. You can monitor its size by listening -
100 to this signal. -
101 -
102 The readyRead() signal is emitted every time a new chunk of data -
103 has arrived. bytesAvailable() then returns the number of bytes -
104 that are available for reading. Typically, you would connect the -
105 readyRead() signal to a slot and read all available data there. -
106 If you don't read all the data at once, the remaining data will -
107 still be available later, and any new incoming data will be -
108 appended to QAbstractSocket's internal read buffer. To limit the -
109 size of the read buffer, call setReadBufferSize(). -
110 -
111 To close the socket, call disconnectFromHost(). QAbstractSocket enters -
112 QAbstractSocket::ClosingState. After all pending data has been written to -
113 the socket, QAbstractSocket actually closes the socket, enters -
114 QAbstractSocket::ClosedState, and emits disconnected(). If you want to -
115 abort a connection immediately, discarding all pending data, call abort() -
116 instead. If the remote host closes the connection, QAbstractSocket will -
117 emit error(QAbstractSocket::RemoteHostClosedError), during which the socket -
118 state will still be ConnectedState, and then the disconnected() signal -
119 will be emitted. -
120 -
121 The port and address of the connected peer is fetched by calling -
122 peerPort() and peerAddress(). peerName() returns the host name of -
123 the peer, as passed to connectToHost(). localPort() and -
124 localAddress() return the port and address of the local socket. -
125 -
126 QAbstractSocket provides a set of functions that suspend the -
127 calling thread until certain signals are emitted. These functions -
128 can be used to implement blocking sockets: -
129 -
130 \list -
131 \li waitForConnected() blocks until a connection has been established. -
132 -
133 \li waitForReadyRead() blocks until new data is available for -
134 reading. -
135 -
136 \li waitForBytesWritten() blocks until one payload of data has been -
137 written to the socket. -
138 -
139 \li waitForDisconnected() blocks until the connection has closed. -
140 \endlist -
141 -
142 We show an example: -
143 -
144 \snippet network/tcpwait.cpp 0 -
145 -
146 If \l{QIODevice::}{waitForReadyRead()} returns false, the -
147 connection has been closed or an error has occurred. -
148 -
149 Programming with a blocking socket is radically different from -
150 programming with a non-blocking socket. A blocking socket doesn't -
151 require an event loop and typically leads to simpler code. -
152 However, in a GUI application, blocking sockets should only be -
153 used in non-GUI threads, to avoid freezing the user interface. -
154 See the \l fortuneclient and \l blockingfortuneclient -
155 examples for an overview of both approaches. -
156 -
157 \note We discourage the use of the blocking functions together -
158 with signals. One of the two possibilities should be used. -
159 -
160 QAbstractSocket can be used with QTextStream and QDataStream's -
161 stream operators (operator<<() and operator>>()). There is one -
162 issue to be aware of, though: You must make sure that enough data -
163 is available before attempting to read it using operator>>(). -
164 -
165 \sa QNetworkAccessManager, QTcpServer -
166*/ -
167 -
168/*! -
169 \fn void QAbstractSocket::hostFound() -
170 -
171 This signal is emitted after connectToHost() has been called and -
172 the host lookup has succeeded. -
173 -
174 \note Since Qt 4.6.3 QAbstractSocket may emit hostFound() -
175 directly from the connectToHost() call since a DNS result could have been -
176 cached. -
177 -
178 \sa connected() -
179*/ -
180 -
181/*! -
182 \fn void QAbstractSocket::connected() -
183 -
184 This signal is emitted after connectToHost() has been called and -
185 a connection has been successfully established. -
186 -
187 \note On some operating systems the connected() signal may -
188 be directly emitted from the connectToHost() call for connections -
189 to the localhost. -
190 -
191 \sa connectToHost(), disconnected() -
192*/ -
193 -
194/*! -
195 \fn void QAbstractSocket::disconnected() -
196 -
197 This signal is emitted when the socket has been disconnected. -
198 -
199 \warning If you need to delete the sender() of this signal in a slot connected -
200 to it, use the \l{QObject::deleteLater()}{deleteLater()} function. -
201 -
202 \sa connectToHost(), disconnectFromHost(), abort() -
203*/ -
204 -
205/*! -
206 \fn void QAbstractSocket::error(QAbstractSocket::SocketError socketError) -
207 -
208 This signal is emitted after an error occurred. The \a socketError -
209 parameter describes the type of error that occurred. -
210 -
211 QAbstractSocket::SocketError is not a registered metatype, so for queued -
212 connections, you will have to register it with Q_DECLARE_METATYPE() and -
213 qRegisterMetaType(). -
214 -
215 \sa error(), errorString(), {Creating Custom Qt Types} -
216*/ -
217 -
218/*! -
219 \fn void QAbstractSocket::stateChanged(QAbstractSocket::SocketState socketState) -
220 -
221 This signal is emitted whenever QAbstractSocket's state changes. -
222 The \a socketState parameter is the new state. -
223 -
224 QAbstractSocket::SocketState is not a registered metatype, so for queued -
225 connections, you will have to register it with Q_DECLARE_METATYPE() and -
226 qRegisterMetaType(). -
227 -
228 \sa state(), {Creating Custom Qt Types} -
229*/ -
230 -
231/*! -
232 \fn void QAbstractSocket::proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator) -
233 \since 4.3 -
234 -
235 This signal can be emitted when a \a proxy that requires -
236 authentication is used. The \a authenticator object can then be -
237 filled in with the required details to allow authentication and -
238 continue the connection. -
239 -
240 \note It is not possible to use a QueuedConnection to connect to -
241 this signal, as the connection will fail if the authenticator has -
242 not been filled in with new information when the signal returns. -
243 -
244 \sa QAuthenticator, QNetworkProxy -
245*/ -
246 -
247/*! -
248 \enum QAbstractSocket::NetworkLayerProtocol -
249 -
250 This enum describes the network layer protocol values used in Qt. -
251 -
252 \value IPv4Protocol IPv4 -
253 \value IPv6Protocol IPv6 -
254 \value AnyIPProtocol Either IPv4 or IPv6 -
255 \value UnknownNetworkLayerProtocol Other than IPv4 and IPv6 -
256 -
257 \sa QHostAddress::protocol() -
258*/ -
259 -
260/*! -
261 \enum QAbstractSocket::SocketType -
262 -
263 This enum describes the transport layer protocol. -
264 -
265 \value TcpSocket TCP -
266 \value UdpSocket UDP -
267 \value UnknownSocketType Other than TCP and UDP -
268 -
269 \sa QAbstractSocket::socketType() -
270*/ -
271 -
272/*! -
273 \enum QAbstractSocket::SocketError -
274 -
275 This enum describes the socket errors that can occur. -
276 -
277 \value ConnectionRefusedError The connection was refused by the -
278 peer (or timed out). -
279 \value RemoteHostClosedError The remote host closed the -
280 connection. Note that the client socket (i.e., this socket) -
281 will be closed after the remote close notification has -
282 been sent. -
283 \value HostNotFoundError The host address was not found. -
284 \value SocketAccessError The socket operation failed because the -
285 application lacked the required privileges. -
286 \value SocketResourceError The local system ran out of resources -
287 (e.g., too many sockets). -
288 \value SocketTimeoutError The socket operation timed out. -
289 \value DatagramTooLargeError The datagram was larger than the -
290 operating system's limit (which can be as low as 8192 -
291 bytes). -
292 \value NetworkError An error occurred with the network (e.g., the -
293 network cable was accidentally plugged out). -
294 \value AddressInUseError The address specified to QAbstractSocket::bind() is -
295 already in use and was set to be exclusive. -
296 \value SocketAddressNotAvailableError The address specified to -
297 QAbstractSocket::bind() does not belong to the host. -
298 \value UnsupportedSocketOperationError The requested socket operation is -
299 not supported by the local operating system (e.g., lack of -
300 IPv6 support). -
301 \value ProxyAuthenticationRequiredError The socket is using a proxy, and -
302 the proxy requires authentication. -
303 \value SslHandshakeFailedError The SSL/TLS handshake failed, so -
304 the connection was closed (only used in QSslSocket) -
305 \value UnfinishedSocketOperationError Used by QAbstractSocketEngine only, -
306 The last operation attempted has not finished yet (still in progress in -
307 the background). -
308 \value ProxyConnectionRefusedError Could not contact the proxy server because -
309 the connection to that server was denied -
310 \value ProxyConnectionClosedError The connection to the proxy server was closed -
311 unexpectedly (before the connection to the final peer was established) -
312 \value ProxyConnectionTimeoutError The connection to the proxy server timed out -
313 or the proxy server stopped responding in the authentication phase. -
314 \value ProxyNotFoundError The proxy address set with setProxy() (or the application -
315 proxy) was not found. -
316 \value ProxyProtocolError The connection negotiation with the proxy server failed, -
317 because the response from the proxy server could not be understood. -
318 \value OperationError An operation was attempted while the socket was in a state that -
319 did not permit it. -
320 \value SslInternalError The SSL library being used reported an internal error. This is -
321 probably the result of a bad installation or misconfiguration of the library. -
322 \value SslInvalidUserDataError Invalid data (certificate, key, cypher, etc.) was -
323 provided and its use resulted in an error in the SSL library. -
324 \value TemporaryError A temporary error occurred (e.g., operation would block and socket -
325 is non-blocking). -
326 -
327 \value UnknownSocketError An unidentified error occurred. -
328 \sa QAbstractSocket::error() -
329*/ -
330 -
331/*! -
332 \enum QAbstractSocket::SocketState -
333 -
334 This enum describes the different states in which a socket can be. -
335 -
336 \value UnconnectedState The socket is not connected. -
337 \value HostLookupState The socket is performing a host name lookup. -
338 \value ConnectingState The socket has started establishing a connection. -
339 \value ConnectedState A connection is established. -
340 \value BoundState The socket is bound to an address and port. -
341 \value ClosingState The socket is about to close (data may still -
342 be waiting to be written). -
343 \value ListeningState For internal use only. -
344 -
345 \sa QAbstractSocket::state() -
346*/ -
347 -
348/*! -
349 \enum QAbstractSocket::SocketOption -
350 \since 4.6 -
351 -
352 This enum represents the options that can be set on a socket. If -
353 desired, they can be set after having received the connected() -
354 signal from the socket or after having received a new socket from -
355 a QTcpServer. -
356 -
357 \value LowDelayOption Try to optimize the socket for low -
358 latency. For a QTcpSocket this would set the TCP_NODELAY option -
359 and disable Nagle's algorithm. Set this to 1 to enable. -
360 -
361 \value KeepAliveOption Set this to 1 to enable the SO_KEEPALIVE -
362 socket option -
363 -
364 \value MulticastTtlOption Set this to an integer value to set -
365 IP_MULTICAST_TTL (TTL for multicast datagrams) socket option. -
366 -
367 \value MulticastLoopbackOption Set this to 1 to enable the -
368 IP_MULTICAST_LOOP (multicast loopback) socket option. -
369 -
370 \value TypeOfServiceOption This option is not supported on -
371 Windows. This maps to the IP_TOS socket option. -
372 -
373 Possible values for the \e{TypeOfServiceOption} are: -
374 -
375 \table -
376 \header \li Value \li Description -
377 \row \li 224 \li Network control -
378 \row \li 192 \li Internetwork control -
379 \row \li 160 \li CRITIC/ECP -
380 \row \li 128 \li Flash override -
381 \row \li 96 \li Flash -
382 \row \li 64 \li Immediate -
383 \row \li 32 \li Priority -
384 \row \li 0 \li Routine -
385 \endtable -
386 -
387 \sa QAbstractSocket::setSocketOption(), QAbstractSocket::socketOption() -
388*/ -
389 -
390/*! \enum QAbstractSocket::BindFlag -
391 \since 5.0 -
392 -
393 This enum describes the different flags you can pass to modify the -
394 behavior of QAbstractSocket::bind(). -
395 -
396 \value ShareAddress Allow other services to bind to the same address -
397 and port. This is useful when multiple processes share -
398 the load of a single service by listening to the same address and port -
399 (e.g., a web server with several pre-forked listeners can greatly -
400 improve response time). However, because any service is allowed to -
401 rebind, this option is subject to certain security considerations. -
402 Note that by combining this option with ReuseAddressHint, you will -
403 also allow your service to rebind an existing shared address. On -
404 Unix, this is equivalent to the SO_REUSEADDR socket option. On Windows, -
405 this option is ignored. -
406 -
407 \value DontShareAddress Bind the address and port exclusively, so that -
408 no other services are allowed to rebind. By passing this option to -
409 QAbstractSocket::bind(), you are guaranteed that on successs, your service -
410 is the only one that listens to the address and port. No services are -
411 allowed to rebind, even if they pass ReuseAddressHint. This option -
412 provides more security than ShareAddress, but on certain operating -
413 systems, it requires you to run the server with administrator privileges. -
414 On Unix and Mac OS X, not sharing is the default behavior for binding -
415 an address and port, so this option is ignored. On Windows, this -
416 option uses the SO_EXCLUSIVEADDRUSE socket option. -
417 -
418 \value ReuseAddressHint Provides a hint to QAbstractSocket that it should try -
419 to rebind the service even if the address and port are already bound by -
420 another socket. On Windows, this is equivalent to the SO_REUSEADDR -
421 socket option. On Unix, this option is ignored. -
422 -
423 \value DefaultForPlatform The default option for the current platform. -
424 On Unix and Mac OS X, this is equivalent to (DontShareAddress -
425 + ReuseAddressHint), and on Windows, its equivalent to ShareAddress. -
426*/ -
427 -
428/*! \enum QAbstractSocket::PauseMode -
429 \since 5.0 -
430 -
431 This enum describes the behavior of when the socket should hold -
432 back with continuing data transfer. -
433 The only notification currently supported is QSslSocket::sslErrors(). -
434 -
435 \value PauseNever Do not pause data transfer on the socket. This is the -
436 default and matches the behaviour of Qt 4. -
437 \value PauseOnSslErrors Pause data transfer on the socket upon receiving an -
438 SSL error notification. I.E. QSslSocket::sslErrors(). -
439*/ -
440 -
441#include "qabstractsocket.h" -
442#include "qabstractsocket_p.h" -
443 -
444#include "private/qhostinfo_p.h" -
445#include "private/qnetworksession_p.h" -
446 -
447#include <qabstracteventdispatcher.h> -
448#include <qhostaddress.h> -
449#include <qhostinfo.h> -
450#include <qmetaobject.h> -
451#include <qpointer.h> -
452#include <qtimer.h> -
453#include <qelapsedtimer.h> -
454#include <qscopedvaluerollback.h> -
455 -
456#ifndef QT_NO_SSL -
457#include <QtNetwork/qsslsocket.h> -
458#endif -
459 -
460#include <private/qthread_p.h> -
461 -
462#ifdef QABSTRACTSOCKET_DEBUG -
463#include <qdebug.h> -
464#endif -
465 -
466#include <time.h> -
467 -
468#define Q_CHECK_SOCKETENGINE(returnValue) do { \ -
469 if (!d->socketEngine) { \ -
470 return returnValue; \ -
471 } } while (0) -
472 -
473#ifndef QABSTRACTSOCKET_BUFFERSIZE -
474#define QABSTRACTSOCKET_BUFFERSIZE 32768 -
475#endif -
476#define QT_CONNECT_TIMEOUT 30000 -
477#define QT_TRANSFER_TIMEOUT 120000 -
478 -
479QT_BEGIN_NAMESPACE -
480 -
481#if defined QABSTRACTSOCKET_DEBUG -
482QT_BEGIN_INCLUDE_NAMESPACE -
483#include <qstring.h> -
484#include <ctype.h> -
485QT_END_INCLUDE_NAMESPACE -
486 -
487/* -
488 Returns a human readable representation of the first \a len -
489 characters in \a data. -
490*/ -
491static QByteArray qt_prettyDebug(const char *data, int len, int maxLength) -
492{ -
493 if (!data) return "(null)"; -
494 QByteArray out; -
495 for (int i = 0; i < len; ++i) { -
496 char c = data[i]; -
497 if (isprint(int(uchar(c)))) { -
498 out += c; -
499 } else switch (c) { -
500 case '\n': out += "\\n"; break; -
501 case '\r': out += "\\r"; break; -
502 case '\t': out += "\\t"; break; -
503 default: -
504 QString tmp; -
505 tmp.sprintf("\\%o", c); -
506 out += tmp.toLatin1(); -
507 } -
508 } -
509 -
510 if (len < maxLength) -
511 out += "..."; -
512 -
513 return out; -
514} -
515#endif -
516 -
517static bool isProxyError(QAbstractSocket::SocketError error) -
518{ -
519 switch (error) { -
520 case QAbstractSocket::ProxyAuthenticationRequiredError: -
521 case QAbstractSocket::ProxyConnectionRefusedError: -
522 case QAbstractSocket::ProxyConnectionClosedError: -
523 case QAbstractSocket::ProxyConnectionTimeoutError: -
524 case QAbstractSocket::ProxyNotFoundError: -
525 case QAbstractSocket::ProxyProtocolError: -
526 return true;
executed: return true;
Execution Count:5
5
527 default: -
528 return false;
executed: return false;
Execution Count:10
10
529 } -
530}
never executed: }
0
531 -
532/*! \internal -
533 -
534 Constructs a QAbstractSocketPrivate. Initializes all members. -
535*/ -
536QAbstractSocketPrivate::QAbstractSocketPrivate() -
537 : readSocketNotifierCalled(false), -
538 readSocketNotifierState(false), -
539 readSocketNotifierStateSet(false), -
540 emittedReadyRead(false), -
541 emittedBytesWritten(false), -
542 abortCalled(false), -
543 closeCalled(false), -
544 pendingClose(false), -
545 pauseMode(QAbstractSocket::PauseNever), -
546 port(0), -
547 localPort(0), -
548 peerPort(0), -
549 socketEngine(0), -
550 cachedSocketDescriptor(-1), -
551 readBufferMaxSize(0), -
552 writeBuffer(QABSTRACTSOCKET_BUFFERSIZE), -
553 isBuffered(false), -
554 blockingTimeout(30000), -
555 connectTimer(0), -
556 disconnectTimer(0), -
557 connectTimeElapsed(0), -
558 hostLookupId(-1), -
559 socketType(QAbstractSocket::UnknownSocketType), -
560 state(QAbstractSocket::UnconnectedState), -
561 socketError(QAbstractSocket::UnknownSocketError), -
562 preferredNetworkLayerProtocol(QAbstractSocket::UnknownNetworkLayerProtocol) -
563{ -
564}
executed: }
Execution Count:3146
3146
565 -
566/*! \internal -
567 -
568 Destructs the QAbstractSocket. If the socket layer is open, it -
569 will be reset. -
570*/ -
571QAbstractSocketPrivate::~QAbstractSocketPrivate() -
572{ -
573} -
574 -
575/*! \internal -
576 -
577 Resets the socket layer, clears the read and write buffers and -
578 deletes any socket notifiers. -
579*/ -
580void QAbstractSocketPrivate::resetSocketLayer() -
581{ -
582#if defined (QABSTRACTSOCKET_DEBUG) -
583 qDebug("QAbstractSocketPrivate::resetSocketLayer()"); -
584#endif -
585 -
586 if (socketEngine) {
evaluated: socketEngine
TRUEFALSE
yes
Evaluation Count:3040
yes
Evaluation Count:3387
3040-3387
587 socketEngine->close();
executed (the execution status of this line is deduced): socketEngine->close();
-
588 socketEngine->disconnect();
executed (the execution status of this line is deduced): socketEngine->disconnect();
-
589 delete socketEngine;
executed (the execution status of this line is deduced): delete socketEngine;
-
590 socketEngine = 0;
executed (the execution status of this line is deduced): socketEngine = 0;
-
591 cachedSocketDescriptor = -1;
executed (the execution status of this line is deduced): cachedSocketDescriptor = -1;
-
592 }
executed: }
Execution Count:3040
3040
593 if (connectTimer)
evaluated: connectTimer
TRUEFALSE
yes
Evaluation Count:1250
yes
Evaluation Count:5177
1250-5177
594 connectTimer->stop();
executed: connectTimer->stop();
Execution Count:1250
1250
595 if (disconnectTimer)
partially evaluated: disconnectTimer
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6427
0-6427
596 disconnectTimer->stop();
never executed: disconnectTimer->stop();
0
597}
executed: }
Execution Count:6427
6427
598 -
599/*! \internal -
600 -
601 Initializes the socket layer to by of type \a type, using the -
602 network layer protocol \a protocol. Resets the socket layer first -
603 if it's already initialized. Sets up the socket notifiers. -
604*/ -
605bool QAbstractSocketPrivate::initSocketLayer(QAbstractSocket::NetworkLayerProtocol protocol) -
606{ -
607#ifdef QT_NO_NETWORKPROXY -
608 // this is here to avoid a duplication of the call to createSocketEngine below -
609 static const QNetworkProxy &proxyInUse = *(QNetworkProxy *)0; -
610#endif -
611 -
612 Q_Q(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocket * const q = q_func();
-
613#if defined (QABSTRACTSOCKET_DEBUG) -
614 QString typeStr; -
615 if (q->socketType() == QAbstractSocket::TcpSocket) typeStr = QLatin1String("TcpSocket"); -
616 else if (q->socketType() == QAbstractSocket::UdpSocket) typeStr = QLatin1String("UdpSocket"); -
617 else typeStr = QLatin1String("UnknownSocketType"); -
618 QString protocolStr; -
619 if (protocol == QAbstractSocket::IPv4Protocol) protocolStr = QLatin1String("IPv4Protocol"); -
620 else if (protocol == QAbstractSocket::IPv6Protocol) protocolStr = QLatin1String("IPv6Protocol"); -
621 else protocolStr = QLatin1String("UnknownNetworkLayerProtocol"); -
622#endif -
623 -
624 resetSocketLayer();
executed (the execution status of this line is deduced): resetSocketLayer();
-
625 socketEngine = QAbstractSocketEngine::createSocketEngine(q->socketType(), proxyInUse, q);
executed (the execution status of this line is deduced): socketEngine = QAbstractSocketEngine::createSocketEngine(q->socketType(), proxyInUse, q);
-
626 if (!socketEngine) {
partially evaluated: !socketEngine
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2464
0-2464
627 socketError = QAbstractSocket::UnsupportedSocketOperationError;
never executed (the execution status of this line is deduced): socketError = QAbstractSocket::UnsupportedSocketOperationError;
-
628 q->setErrorString(QAbstractSocket::tr("Operation on socket is not supported"));
never executed (the execution status of this line is deduced): q->setErrorString(QAbstractSocket::tr("Operation on socket is not supported"));
-
629 return false;
never executed: return false;
0
630 } -
631#ifndef QT_NO_BEARERMANAGEMENT -
632 //copy network session down to the socket engine (if it has been set) -
633 socketEngine->setProperty("_q_networksession", q->property("_q_networksession"));
executed (the execution status of this line is deduced): socketEngine->setProperty("_q_networksession", q->property("_q_networksession"));
-
634#endif -
635 if (!socketEngine->initialize(q->socketType(), protocol)) {
partially evaluated: !socketEngine->initialize(q->socketType(), protocol)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2464
0-2464
636#if defined (QABSTRACTSOCKET_DEBUG) -
637 qDebug("QAbstractSocketPrivate::initSocketLayer(%s, %s) failed (%s)", -
638 typeStr.toLatin1().constData(), protocolStr.toLatin1().constData(), -
639 socketEngine->errorString().toLatin1().constData()); -
640#endif -
641 socketError = socketEngine->error();
never executed (the execution status of this line is deduced): socketError = socketEngine->error();
-
642 q->setErrorString(socketEngine->errorString());
never executed (the execution status of this line is deduced): q->setErrorString(socketEngine->errorString());
-
643 return false;
never executed: return false;
0
644 } -
645 -
646 if (threadData->eventDispatcher)
partially evaluated: threadData->eventDispatcher
TRUEFALSE
yes
Evaluation Count:2464
no
Evaluation Count:0
0-2464
647 socketEngine->setReceiver(this);
executed: socketEngine->setReceiver(this);
Execution Count:2464
2464
648 -
649#if defined (QABSTRACTSOCKET_DEBUG) -
650 qDebug("QAbstractSocketPrivate::initSocketLayer(%s, %s) success", -
651 typeStr.toLatin1().constData(), protocolStr.toLatin1().constData()); -
652#endif -
653 return true;
executed: return true;
Execution Count:2464
2464
654} -
655 -
656/*! \internal -
657 -
658 Slot connected to the read socket notifier. This slot is called -
659 when new data is available for reading, or when the socket has -
660 been closed. Handles recursive calls. -
661*/ -
662bool QAbstractSocketPrivate::canReadNotification() -
663{ -
664 Q_Q(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocket * const q = q_func();
-
665#if defined (QABSTRACTSOCKET_DEBUG) -
666 qDebug("QAbstractSocketPrivate::canReadNotification()"); -
667#endif -
668 -
669 // Prevent recursive calls -
670 if (readSocketNotifierCalled) {
partially evaluated: readSocketNotifierCalled
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:22784
0-22784
671 if (!readSocketNotifierStateSet) {
never evaluated: !readSocketNotifierStateSet
0
672 readSocketNotifierStateSet = true;
never executed (the execution status of this line is deduced): readSocketNotifierStateSet = true;
-
673 readSocketNotifierState = socketEngine->isReadNotificationEnabled();
never executed (the execution status of this line is deduced): readSocketNotifierState = socketEngine->isReadNotificationEnabled();
-
674 socketEngine->setReadNotificationEnabled(false);
never executed (the execution status of this line is deduced): socketEngine->setReadNotificationEnabled(false);
-
675 }
never executed: }
0
676 }
never executed: }
0
677 QScopedValueRollback<bool> rsncrollback(readSocketNotifierCalled);
executed (the execution status of this line is deduced): QScopedValueRollback<bool> rsncrollback(readSocketNotifierCalled);
-
678 readSocketNotifierCalled = true;
executed (the execution status of this line is deduced): readSocketNotifierCalled = true;
-
679 -
680 if (!isBuffered)
evaluated: !isBuffered
TRUEFALSE
yes
Evaluation Count:6710
yes
Evaluation Count:16074
6710-16074
681 socketEngine->setReadNotificationEnabled(false);
executed: socketEngine->setReadNotificationEnabled(false);
Execution Count:6710
6710
682 -
683 // If buffered, read data from the socket into the read buffer -
684 qint64 newBytes = 0;
executed (the execution status of this line is deduced): qint64 newBytes = 0;
-
685 if (isBuffered) {
evaluated: isBuffered
TRUEFALSE
yes
Evaluation Count:16074
yes
Evaluation Count:6710
6710-16074
686 // Return if there is no space in the buffer -
687 if (readBufferMaxSize && buffer.size() >= readBufferMaxSize) {
evaluated: readBufferMaxSize
TRUEFALSE
yes
Evaluation Count:1174
yes
Evaluation Count:14900
partially evaluated: buffer.size() >= readBufferMaxSize
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1174
0-14900
688#if defined (QABSTRACTSOCKET_DEBUG) -
689 qDebug("QAbstractSocketPrivate::canReadNotification() buffer is full"); -
690#endif -
691 return false;
never executed: return false;
0
692 } -
693 -
694 // If reading from the socket fails after getting a read -
695 // notification, close the socket. -
696 newBytes = buffer.size();
executed (the execution status of this line is deduced): newBytes = buffer.size();
-
697 if (!readFromSocket()) {
evaluated: !readFromSocket()
TRUEFALSE
yes
Evaluation Count:205
yes
Evaluation Count:15869
205-15869
698#if defined (QABSTRACTSOCKET_DEBUG) -
699 qDebug("QAbstractSocketPrivate::canReadNotification() disconnecting socket"); -
700#endif -
701 q->disconnectFromHost();
executed (the execution status of this line is deduced): q->disconnectFromHost();
-
702 return false;
executed: return false;
Execution Count:205
205
703 } -
704 newBytes = buffer.size() - newBytes;
executed (the execution status of this line is deduced): newBytes = buffer.size() - newBytes;
-
705 -
706 // If read buffer is full, disable the read socket notifier. -
707 if (readBufferMaxSize && buffer.size() == readBufferMaxSize) {
evaluated: readBufferMaxSize
TRUEFALSE
yes
Evaluation Count:1167
yes
Evaluation Count:14702
evaluated: buffer.size() == readBufferMaxSize
TRUEFALSE
yes
Evaluation Count:37
yes
Evaluation Count:1130
37-14702
708 socketEngine->setReadNotificationEnabled(false);
executed (the execution status of this line is deduced): socketEngine->setReadNotificationEnabled(false);
-
709 }
executed: }
Execution Count:37
37
710 }
executed: }
Execution Count:15869
15869
711 -
712 // only emit readyRead() when not recursing, and only if there is data available -
713 bool hasData = newBytes > 0
evaluated: newBytes > 0
TRUEFALSE
yes
Evaluation Count:15869
yes
Evaluation Count:6710
6710-15869
714#ifndef QT_NO_UDPSOCKET
executed (the execution status of this line is deduced):
-
715 || (!isBuffered && socketType != QAbstractSocket::TcpSocket && socketEngine && socketEngine->hasPendingDatagrams())
partially evaluated: !isBuffered
TRUEFALSE
yes
Evaluation Count:6710
no
Evaluation Count:0
evaluated: socketType != QAbstractSocket::TcpSocket
TRUEFALSE
yes
Evaluation Count:710
yes
Evaluation Count:6000
partially evaluated: socketEngine
TRUEFALSE
yes
Evaluation Count:710
no
Evaluation Count:0
evaluated: socketEngine->hasPendingDatagrams()
TRUEFALSE
yes
Evaluation Count:690
yes
Evaluation Count:20
0-6710
716#endif
executed (the execution status of this line is deduced):
-
717 || (!isBuffered && socketType == QAbstractSocket::TcpSocket && socketEngine)
partially evaluated: !isBuffered
TRUEFALSE
yes
Evaluation Count:6020
no
Evaluation Count:0
evaluated: socketType == QAbstractSocket::TcpSocket
TRUEFALSE
yes
Evaluation Count:6000
yes
Evaluation Count:20
partially evaluated: socketEngine
TRUEFALSE
yes
Evaluation Count:6000
no
Evaluation Count:0
0-6020
718 ;
executed (the execution status of this line is deduced): ;
-
719 -
720 if (!emittedReadyRead && hasData) {
partially evaluated: !emittedReadyRead
TRUEFALSE
yes
Evaluation Count:22579
no
Evaluation Count:0
evaluated: hasData
TRUEFALSE
yes
Evaluation Count:22559
yes
Evaluation Count:20
0-22579
721 QScopedValueRollback<bool> r(emittedReadyRead);
executed (the execution status of this line is deduced): QScopedValueRollback<bool> r(emittedReadyRead);
-
722 emittedReadyRead = true;
executed (the execution status of this line is deduced): emittedReadyRead = true;
-
723 emit q->readyRead();
executed (the execution status of this line is deduced): q->readyRead();
-
724 }
executed: }
Execution Count:22559
22559
725 -
726 // If we were closed as a result of the readyRead() signal, -
727 // return. -
728 if (state == QAbstractSocket::UnconnectedState || state == QAbstractSocket::ClosingState) {
evaluated: state == QAbstractSocket::UnconnectedState
TRUEFALSE
yes
Evaluation Count:347
yes
Evaluation Count:22232
evaluated: state == QAbstractSocket::ClosingState
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:22231
1-22232
729#if defined (QABSTRACTSOCKET_DEBUG) -
730 qDebug("QAbstractSocketPrivate::canReadNotification() socket is closing - returning"); -
731#endif -
732 return true;
executed: return true;
Execution Count:348
348
733 } -
734 -
735 if (!hasData && socketEngine)
evaluated: !hasData
TRUEFALSE
yes
Evaluation Count:20
yes
Evaluation Count:22211
partially evaluated: socketEngine
TRUEFALSE
yes
Evaluation Count:20
no
Evaluation Count:0
0-22211
736 socketEngine->setReadNotificationEnabled(true);
executed: socketEngine->setReadNotificationEnabled(true);
Execution Count:20
20
737 -
738 // reset the read socket notifier state if we reentered inside the -
739 // readyRead() connected slot. -
740 if (readSocketNotifierStateSet && socketEngine &&
partially evaluated: readSocketNotifierStateSet
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:22231
never evaluated: socketEngine
0-22231
741 readSocketNotifierState != socketEngine->isReadNotificationEnabled()) {
never evaluated: readSocketNotifierState != socketEngine->isReadNotificationEnabled()
0
742 socketEngine->setReadNotificationEnabled(readSocketNotifierState);
never executed (the execution status of this line is deduced): socketEngine->setReadNotificationEnabled(readSocketNotifierState);
-
743 readSocketNotifierStateSet = false;
never executed (the execution status of this line is deduced): readSocketNotifierStateSet = false;
-
744 }
never executed: }
0
745 return true;
executed: return true;
Execution Count:22231
22231
746} -
747 -
748/*! \internal -
749 -
750 Slot connected to the close socket notifier. It's called when the -
751 socket is closed. -
752*/ -
753void QAbstractSocketPrivate::canCloseNotification() -
754{ -
755 Q_Q(QAbstractSocket);
never executed (the execution status of this line is deduced): QAbstractSocket * const q = q_func();
-
756 -
757#if defined (QABSTRACTSOCKET_DEBUG) -
758 qDebug("QAbstractSocketPrivate::canCloseNotification()"); -
759#endif -
760 -
761 qint64 newBytes = 0;
never executed (the execution status of this line is deduced): qint64 newBytes = 0;
-
762 if (isBuffered) {
never evaluated: isBuffered
0
763 // Try to read to the buffer, if the read fail we can close the socket. -
764 newBytes = buffer.size();
never executed (the execution status of this line is deduced): newBytes = buffer.size();
-
765 if (!readFromSocket()) {
never evaluated: !readFromSocket()
0
766 q->disconnectFromHost();
never executed (the execution status of this line is deduced): q->disconnectFromHost();
-
767 return;
never executed: return;
0
768 } -
769 newBytes = buffer.size() - newBytes;
never executed (the execution status of this line is deduced): newBytes = buffer.size() - newBytes;
-
770 if (newBytes) {
never evaluated: newBytes
0
771 // If there was still some data to be read from the socket -
772 // then we could get another FD_READ. The disconnect will -
773 // then occur when we read from the socket again and fail -
774 // in canReadNotification or by the manually created -
775 // closeNotification below. -
776 emit q->readyRead();
never executed (the execution status of this line is deduced): q->readyRead();
-
777 -
778 QMetaObject::invokeMethod(socketEngine, "closeNotification", Qt::QueuedConnection);
never executed (the execution status of this line is deduced): QMetaObject::invokeMethod(socketEngine, "closeNotification", Qt::QueuedConnection);
-
779 }
never executed: }
0
780 } else if (socketType == QAbstractSocket::TcpSocket && socketEngine) {
never executed: }
never evaluated: socketType == QAbstractSocket::TcpSocket
never evaluated: socketEngine
0
781 emit q->readyRead();
never executed (the execution status of this line is deduced): q->readyRead();
-
782 }
never executed: }
0
783} -
784 -
785 -
786/*! \internal -
787 -
788 Slot connected to the write socket notifier. It's called during a -
789 delayed connect or when the socket is ready for writing. -
790*/ -
791bool QAbstractSocketPrivate::canWriteNotification() -
792{ -
793#if defined (Q_OS_WIN) -
794 if (socketEngine && socketEngine->isWriteNotificationEnabled()) -
795 socketEngine->setWriteNotificationEnabled(false); -
796#endif -
797 -
798#if defined (QABSTRACTSOCKET_DEBUG) -
799 qDebug("QAbstractSocketPrivate::canWriteNotification() flushing"); -
800#endif -
801 int tmp = writeBuffer.size();
executed (the execution status of this line is deduced): int tmp = writeBuffer.size();
-
802 flush();
executed (the execution status of this line is deduced): flush();
-
803 -
804 if (socketEngine) {
evaluated: socketEngine
TRUEFALSE
yes
Evaluation Count:12359
yes
Evaluation Count:230
230-12359
805#if defined (Q_OS_WIN) -
806 if (!writeBuffer.isEmpty()) -
807 socketEngine->setWriteNotificationEnabled(true); -
808#else -
809 if (writeBuffer.isEmpty() && socketEngine->bytesToWrite() == 0)
evaluated: writeBuffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:6944
yes
Evaluation Count:5415
evaluated: socketEngine->bytesToWrite() == 0
TRUEFALSE
yes
Evaluation Count:6888
yes
Evaluation Count:56
56-6944
810 socketEngine->setWriteNotificationEnabled(false);
executed: socketEngine->setWriteNotificationEnabled(false);
Execution Count:6888
6888
811#endif -
812 }
executed: }
Execution Count:12359
12359
813 -
814 return (writeBuffer.size() < tmp);
executed: return (writeBuffer.size() < tmp);
Execution Count:12589
12589
815} -
816 -
817/*! \internal -
818 -
819 Slot connected to a notification of connection status -
820 change. Either we finished connecting or we failed to connect. -
821*/ -
822void QAbstractSocketPrivate::connectionNotification() -
823{ -
824 // If in connecting state, check if the connection has been -
825 // established, otherwise flush pending data. -
826 if (state == QAbstractSocket::ConnectingState) {
partially evaluated: state == QAbstractSocket::ConnectingState
TRUEFALSE
yes
Evaluation Count:839
no
Evaluation Count:0
0-839
827#if defined (QABSTRACTSOCKET_DEBUG) -
828 qDebug("QAbstractSocketPrivate::connectionNotification() testing connection"); -
829#endif -
830 _q_testConnection();
executed (the execution status of this line is deduced): _q_testConnection();
-
831 }
executed: }
Execution Count:839
839
832}
executed: }
Execution Count:839
839
833 -
834/*! \internal -
835 -
836 Writes pending data in the write buffers to the socket. The -
837 function writes as much as it can without blocking. -
838 -
839 It is usually invoked by canWriteNotification after one or more -
840 calls to write(). -
841 -
842 Emits bytesWritten(). -
843*/ -
844bool QAbstractSocketPrivate::flush() -
845{ -
846 Q_Q(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocket * const q = q_func();
-
847 if (!socketEngine || !socketEngine->isValid() || (writeBuffer.isEmpty()
partially evaluated: !socketEngine
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:24771
partially evaluated: !socketEngine->isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:24771
evaluated: writeBuffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:710
yes
Evaluation Count:24061
0-24771
848 && socketEngine->bytesToWrite() == 0)) {
evaluated: socketEngine->bytesToWrite() == 0
TRUEFALSE
yes
Evaluation Count:693
yes
Evaluation Count:17
17-693
849#if defined (QABSTRACTSOCKET_DEBUG) -
850 qDebug("QAbstractSocketPrivate::flush() nothing to do: valid ? %s, writeBuffer.isEmpty() ? %s", -
851 (socketEngine && socketEngine->isValid()) ? "yes" : "no", writeBuffer.isEmpty() ? "yes" : "no"); -
852#endif -
853 -
854 // this covers the case when the buffer was empty, but we had to wait for the socket engine to finish -
855 if (state == QAbstractSocket::ClosingState)
partially evaluated: state == QAbstractSocket::ClosingState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:693
0-693
856 q->disconnectFromHost();
never executed: q->disconnectFromHost();
0
857 -
858 return false;
executed: return false;
Execution Count:693
693
859 } -
860 -
861 int nextSize = writeBuffer.nextDataBlockSize();
executed (the execution status of this line is deduced): int nextSize = writeBuffer.nextDataBlockSize();
-
862 const char *ptr = writeBuffer.readPointer();
executed (the execution status of this line is deduced): const char *ptr = writeBuffer.readPointer();
-
863 -
864 // Attempt to write it all in one chunk. -
865 qint64 written = socketEngine->write(ptr, nextSize);
executed (the execution status of this line is deduced): qint64 written = socketEngine->write(ptr, nextSize);
-
866 if (written < 0) {
evaluated: written < 0
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:24072
6-24072
867 socketError = socketEngine->error();
executed (the execution status of this line is deduced): socketError = socketEngine->error();
-
868 q->setErrorString(socketEngine->errorString());
executed (the execution status of this line is deduced): q->setErrorString(socketEngine->errorString());
-
869#if defined (QABSTRACTSOCKET_DEBUG) -
870 qDebug() << "QAbstractSocketPrivate::flush() write error, aborting." << socketEngine->errorString(); -
871#endif -
872 emit q->error(socketError);
executed (the execution status of this line is deduced): q->error(socketError);
-
873 // an unexpected error so close the socket. -
874 q->abort();
executed (the execution status of this line is deduced): q->abort();
-
875 return false;
executed: return false;
Execution Count:6
6
876 } -
877 -
878#if defined (QABSTRACTSOCKET_DEBUG) -
879 qDebug("QAbstractSocketPrivate::flush() %lld bytes written to the network", -
880 written); -
881#endif -
882 -
883 // Remove what we wrote so far. -
884 writeBuffer.free(written);
executed (the execution status of this line is deduced): writeBuffer.free(written);
-
885 if (written > 0) {
evaluated: written > 0
TRUEFALSE
yes
Evaluation Count:24046
yes
Evaluation Count:26
26-24046
886 // Don't emit bytesWritten() recursively. -
887 if (!emittedBytesWritten) {
partially evaluated: !emittedBytesWritten
TRUEFALSE
yes
Evaluation Count:24046
no
Evaluation Count:0
0-24046
888 QScopedValueRollback<bool> r(emittedBytesWritten);
executed (the execution status of this line is deduced): QScopedValueRollback<bool> r(emittedBytesWritten);
-
889 emittedBytesWritten = true;
executed (the execution status of this line is deduced): emittedBytesWritten = true;
-
890 emit q->bytesWritten(written);
executed (the execution status of this line is deduced): q->bytesWritten(written);
-
891 }
executed: }
Execution Count:24046
24046
892 }
executed: }
Execution Count:24046
24046
893 -
894 if (writeBuffer.isEmpty() && socketEngine && socketEngine->isWriteNotificationEnabled()
evaluated: writeBuffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:18627
yes
Evaluation Count:5445
evaluated: socketEngine
TRUEFALSE
yes
Evaluation Count:18488
yes
Evaluation Count:139
partially evaluated: socketEngine->isWriteNotificationEnabled()
TRUEFALSE
yes
Evaluation Count:18488
no
Evaluation Count:0
0-18627
895 && !socketEngine->bytesToWrite())
evaluated: !socketEngine->bytesToWrite()
TRUEFALSE
yes
Evaluation Count:18424
yes
Evaluation Count:64
64-18424
896 socketEngine->setWriteNotificationEnabled(false);
executed: socketEngine->setWriteNotificationEnabled(false);
Execution Count:18424
18424
897 if (state == QAbstractSocket::ClosingState)
evaluated: state == QAbstractSocket::ClosingState
TRUEFALSE
yes
Evaluation Count:142
yes
Evaluation Count:23930
142-23930
898 q->disconnectFromHost();
executed: q->disconnectFromHost();
Execution Count:142
142
899 -
900 return true;
executed: return true;
Execution Count:24072
24072
901} -
902 -
903#ifndef QT_NO_NETWORKPROXY -
904/*! \internal -
905 -
906 Resolve the proxy to its final value. -
907*/ -
908void QAbstractSocketPrivate::resolveProxy(const QString &hostname, quint16 port) -
909{ -
910 QList<QNetworkProxy> proxies;
executed (the execution status of this line is deduced): QList<QNetworkProxy> proxies;
-
911 -
912 if (proxy.type() != QNetworkProxy::DefaultProxy) {
evaluated: proxy.type() != QNetworkProxy::DefaultProxy
TRUEFALSE
yes
Evaluation Count:946
yes
Evaluation Count:1634
946-1634
913 // a non-default proxy was set with setProxy -
914 proxies << proxy;
executed (the execution status of this line is deduced): proxies << proxy;
-
915 } else {
executed: }
Execution Count:946
946
916 // try the application settings instead -
917 QNetworkProxyQuery query(hostname, port, QString(),
executed (the execution status of this line is deduced): QNetworkProxyQuery query(hostname, port, QString(),
-
918 socketType == QAbstractSocket::TcpSocket ?
executed (the execution status of this line is deduced): socketType == QAbstractSocket::TcpSocket ?
-
919 QNetworkProxyQuery::TcpSocket :
executed (the execution status of this line is deduced): QNetworkProxyQuery::TcpSocket :
-
920 QNetworkProxyQuery::UdpSocket);
executed (the execution status of this line is deduced): QNetworkProxyQuery::UdpSocket);
-
921 proxies = QNetworkProxyFactory::proxyForQuery(query);
executed (the execution status of this line is deduced): proxies = QNetworkProxyFactory::proxyForQuery(query);
-
922 }
executed: }
Execution Count:1634
1634
923 -
924 // return the first that we can use -
925 foreach (const QNetworkProxy &p, proxies) {
executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(proxies)> _container_(proxies); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QNetworkProxy &p = *_container_.i;; __extension__ ({--_container_.brk; break;})) {
-
926 if (socketType == QAbstractSocket::UdpSocket &&
evaluated: socketType == QAbstractSocket::UdpSocket
TRUEFALSE
yes
Evaluation Count:306
yes
Evaluation Count:2274
306-2274
927 (p.capabilities() & QNetworkProxy::UdpTunnelingCapability) == 0)
partially evaluated: (p.capabilities() & QNetworkProxy::UdpTunnelingCapability) == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:306
0-306
928 continue;
never executed: continue;
0
929 -
930 if (socketType == QAbstractSocket::TcpSocket &&
evaluated: socketType == QAbstractSocket::TcpSocket
TRUEFALSE
yes
Evaluation Count:2274
yes
Evaluation Count:306
306-2274
931 (p.capabilities() & QNetworkProxy::TunnelingCapability) == 0)
partially evaluated: (p.capabilities() & QNetworkProxy::TunnelingCapability) == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2274
0-2274
932 continue;
never executed: continue;
0
933 -
934 proxyInUse = p;
executed (the execution status of this line is deduced): proxyInUse = p;
-
935 return;
executed: return;
Execution Count:2580
2580
936 } -
937 -
938 // no proxy found -
939 // DefaultProxy here will raise an error -
940 proxyInUse = QNetworkProxy();
never executed (the execution status of this line is deduced): proxyInUse = QNetworkProxy();
-
941}
never executed: }
0
942 -
943/*! -
944 \internal -
945 -
946 Starts the connection to \a host, like _q_startConnecting below, -
947 but without hostname resolution. -
948*/ -
949void QAbstractSocketPrivate::startConnectingByName(const QString &host) -
950{ -
951 Q_Q(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocket * const q = q_func();
-
952 if (state == QAbstractSocket::ConnectingState || state == QAbstractSocket::ConnectedState)
partially evaluated: state == QAbstractSocket::ConnectingState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:59
partially evaluated: state == QAbstractSocket::ConnectedState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:59
0-59
953 return;
never executed: return;
0
954 -
955#if defined(QABSTRACTSOCKET_DEBUG) -
956 qDebug("QAbstractSocketPrivate::startConnectingByName(host == %s)", qPrintable(host)); -
957#endif -
958 -
959 // ### Let the socket engine drive this? -
960 state = QAbstractSocket::ConnectingState;
executed (the execution status of this line is deduced): state = QAbstractSocket::ConnectingState;
-
961 emit q->stateChanged(state);
executed (the execution status of this line is deduced): q->stateChanged(state);
-
962 -
963 connectTimeElapsed = 0;
executed (the execution status of this line is deduced): connectTimeElapsed = 0;
-
964 -
965 if (initSocketLayer(QAbstractSocket::UnknownNetworkLayerProtocol)) {
partially evaluated: initSocketLayer(QAbstractSocket::UnknownNetworkLayerProtocol)
TRUEFALSE
yes
Evaluation Count:59
no
Evaluation Count:0
0-59
966 if (socketEngine->connectToHostByName(host, port) ||
partially evaluated: socketEngine->connectToHostByName(host, port)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:59
0-59
967 socketEngine->state() == QAbstractSocket::ConnectingState) {
partially evaluated: socketEngine->state() == QAbstractSocket::ConnectingState
TRUEFALSE
yes
Evaluation Count:59
no
Evaluation Count:0
0-59
968 cachedSocketDescriptor = socketEngine->socketDescriptor();
executed (the execution status of this line is deduced): cachedSocketDescriptor = socketEngine->socketDescriptor();
-
969 -
970 return;
executed: return;
Execution Count:59
59
971 } -
972 -
973 // failed to connect -
974 socketError = socketEngine->error();
never executed (the execution status of this line is deduced): socketError = socketEngine->error();
-
975 q->setErrorString(socketEngine->errorString());
never executed (the execution status of this line is deduced): q->setErrorString(socketEngine->errorString());
-
976 }
never executed: }
0
977 -
978 state = QAbstractSocket::UnconnectedState;
never executed (the execution status of this line is deduced): state = QAbstractSocket::UnconnectedState;
-
979 emit q->error(socketError);
never executed (the execution status of this line is deduced): q->error(socketError);
-
980 emit q->stateChanged(state);
never executed (the execution status of this line is deduced): q->stateChanged(state);
-
981}
never executed: }
0
982 -
983#endif -
984 -
985/*! \internal -
986 -
987 Slot connected to QHostInfo::lookupHost() in connectToHost(). This -
988 function starts the process of connecting to any number of -
989 candidate IP addresses for the host, if it was found. Calls -
990 _q_connectToNextAddress(). -
991*/ -
992void QAbstractSocketPrivate::_q_startConnecting(const QHostInfo &hostInfo) -
993{ -
994 Q_Q(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocket * const q = q_func();
-
995 addresses.clear();
executed (the execution status of this line is deduced): addresses.clear();
-
996 if (state != QAbstractSocket::HostLookupState)
partially evaluated: state != QAbstractSocket::HostLookupState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2100
0-2100
997 return;
never executed: return;
0
998 -
999 if (hostLookupId != -1 && hostLookupId != hostInfo.lookupId()) {
evaluated: hostLookupId != -1
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2098
partially evaluated: hostLookupId != hostInfo.lookupId()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2098
1000 qWarning("QAbstractSocketPrivate::_q_startConnecting() received hostInfo for wrong lookup ID %d expected %d", hostInfo.lookupId(), hostLookupId);
never executed (the execution status of this line is deduced): QMessageLogger("socket/qabstractsocket.cpp", 1000, __PRETTY_FUNCTION__).warning("QAbstractSocketPrivate::_q_startConnecting() received hostInfo for wrong lookup ID %d expected %d", hostInfo.lookupId(), hostLookupId);
-
1001 }
never executed: }
0
1002 -
1003 // Only add the addresses for the preferred network layer. -
1004 // Or all if preferred network layer is not set. -
1005 if (preferredNetworkLayerProtocol == QAbstractSocket::UnknownNetworkLayerProtocol || preferredNetworkLayerProtocol == QAbstractSocket::AnyIPProtocol) {
partially evaluated: preferredNetworkLayerProtocol == QAbstractSocket::UnknownNetworkLayerProtocol
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2100
evaluated: preferredNetworkLayerProtocol == QAbstractSocket::AnyIPProtocol
TRUEFALSE
yes
Evaluation Count:1505
yes
Evaluation Count:595
0-2100
1006 addresses = hostInfo.addresses();
executed (the execution status of this line is deduced): addresses = hostInfo.addresses();
-
1007 } else {
executed: }
Execution Count:1505
1505
1008 foreach (const QHostAddress &address, hostInfo.addresses())
executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(hostInfo.addresses())> _container_(hostInfo.addresses()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QHostAddress &address = *_container_.i;; __extension__ ({--_container_.brk; break;}))
-
1009 if (address.protocol() == preferredNetworkLayerProtocol)
evaluated: address.protocol() == preferredNetworkLayerProtocol
TRUEFALSE
yes
Evaluation Count:595
yes
Evaluation Count:1
1-595
1010 addresses += address;
executed: addresses += address;
Execution Count:595
595
1011 }
executed: }
Execution Count:595
595
1012 -
1013 -
1014#if defined(QABSTRACTSOCKET_DEBUG) -
1015 QString s = QLatin1String("{"); -
1016 for (int i = 0; i < addresses.count(); ++i) { -
1017 if (i != 0) s += QLatin1String(", "); -
1018 s += addresses.at(i).toString(); -
1019 } -
1020 s += QLatin1Char('}'); -
1021 qDebug("QAbstractSocketPrivate::_q_startConnecting(hostInfo == %s)", s.toLatin1().constData()); -
1022#endif -
1023 -
1024 // Try all addresses twice. -
1025 addresses += addresses;
executed (the execution status of this line is deduced): addresses += addresses;
-
1026 -
1027 // If there are no addresses in the host list, report this to the -
1028 // user. -
1029 if (addresses.isEmpty()) {
evaluated: addresses.isEmpty()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:2097
3-2097
1030#if defined(QABSTRACTSOCKET_DEBUG) -
1031 qDebug("QAbstractSocketPrivate::_q_startConnecting(), host not found"); -
1032#endif -
1033 state = QAbstractSocket::UnconnectedState;
executed (the execution status of this line is deduced): state = QAbstractSocket::UnconnectedState;
-
1034 socketError = QAbstractSocket::HostNotFoundError;
executed (the execution status of this line is deduced): socketError = QAbstractSocket::HostNotFoundError;
-
1035 q->setErrorString(QAbstractSocket::tr("Host not found"));
executed (the execution status of this line is deduced): q->setErrorString(QAbstractSocket::tr("Host not found"));
-
1036 emit q->stateChanged(state);
executed (the execution status of this line is deduced): q->stateChanged(state);
-
1037 emit q->error(QAbstractSocket::HostNotFoundError);
executed (the execution status of this line is deduced): q->error(QAbstractSocket::HostNotFoundError);
-
1038 return;
executed: return;
Execution Count:3
3
1039 } -
1040 -
1041 // Enter Connecting state (see also sn_write, which is called by -
1042 // the write socket notifier after connect()) -
1043 state = QAbstractSocket::ConnectingState;
executed (the execution status of this line is deduced): state = QAbstractSocket::ConnectingState;
-
1044 emit q->stateChanged(state);
executed (the execution status of this line is deduced): q->stateChanged(state);
-
1045 -
1046 // Report the successful host lookup -
1047 emit q->hostFound();
executed (the execution status of this line is deduced): q->hostFound();
-
1048 -
1049 // Reset the total time spent connecting. -
1050 connectTimeElapsed = 0;
executed (the execution status of this line is deduced): connectTimeElapsed = 0;
-
1051 -
1052 // The addresses returned by the lookup will be tested one after -
1053 // another by _q_connectToNextAddress(). -
1054 _q_connectToNextAddress();
executed (the execution status of this line is deduced): _q_connectToNextAddress();
-
1055}
executed: }
Execution Count:2097
2097
1056 -
1057/*! \internal -
1058 -
1059 Called by a queued or direct connection from _q_startConnecting() or -
1060 _q_testConnection(), this function takes the first address of the -
1061 pending addresses list and tries to connect to it. If the -
1062 connection succeeds, QAbstractSocket will emit -
1063 connected(). Otherwise, error(ConnectionRefusedError) or -
1064 error(SocketTimeoutError) is emitted. -
1065*/ -
1066void QAbstractSocketPrivate::_q_connectToNextAddress() -
1067{ -
1068 Q_Q(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocket * const q = q_func();
-
1069 do { -
1070 // Check for more pending addresses -
1071 if (addresses.isEmpty()) {
evaluated: addresses.isEmpty()
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:2102
12-2102
1072#if defined(QABSTRACTSOCKET_DEBUG) -
1073 qDebug("QAbstractSocketPrivate::_q_connectToNextAddress(), all addresses failed."); -
1074#endif -
1075 state = QAbstractSocket::UnconnectedState;
executed (the execution status of this line is deduced): state = QAbstractSocket::UnconnectedState;
-
1076 if (socketEngine) {
partially evaluated: socketEngine
TRUEFALSE
yes
Evaluation Count:12
no
Evaluation Count:0
0-12
1077 if ((socketEngine->error() == QAbstractSocket::UnknownSocketError
partially evaluated: (socketEngine->error() == QAbstractSocket::UnknownSocketError )
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
1078#ifdef Q_OS_AIX
partially evaluated: (socketEngine->error() == QAbstractSocket::UnknownSocketError )
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
1079 // On AIX, the second connect call will result in EINVAL and not
partially evaluated: (socketEngine->error() == QAbstractSocket::UnknownSocketError )
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
1080 // ECONNECTIONREFUSED; although the meaning is the same.
partially evaluated: (socketEngine->error() == QAbstractSocket::UnknownSocketError )
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
1081 || socketEngine->error() == QAbstractSocket::UnsupportedSocketOperationError
partially evaluated: (socketEngine->error() == QAbstractSocket::UnknownSocketError )
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
1082#endif
partially evaluated: (socketEngine->error() == QAbstractSocket::UnknownSocketError )
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
1083 ) && socketEngine->state() == QAbstractSocket::ConnectingState) {
partially evaluated: (socketEngine->error() == QAbstractSocket::UnknownSocketError )
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
never evaluated: socketEngine->state() == QAbstractSocket::ConnectingState
0-12
1084 socketError = QAbstractSocket::ConnectionRefusedError;
never executed (the execution status of this line is deduced): socketError = QAbstractSocket::ConnectionRefusedError;
-
1085 q->setErrorString(QAbstractSocket::tr("Connection refused"));
never executed (the execution status of this line is deduced): q->setErrorString(QAbstractSocket::tr("Connection refused"));
-
1086 } else {
never executed: }
0
1087 socketError = socketEngine->error();
executed (the execution status of this line is deduced): socketError = socketEngine->error();
-
1088 q->setErrorString(socketEngine->errorString());
executed (the execution status of this line is deduced): q->setErrorString(socketEngine->errorString());
-
1089 }
executed: }
Execution Count:12
12
1090 } else { -
1091// socketError = QAbstractSocket::ConnectionRefusedError; -
1092// q->setErrorString(QAbstractSocket::tr("Connection refused")); -
1093 }
never executed: }
0
1094 emit q->stateChanged(state);
executed (the execution status of this line is deduced): q->stateChanged(state);
-
1095 emit q->error(socketError);
executed (the execution status of this line is deduced): q->error(socketError);
-
1096 return;
executed: return;
Execution Count:12
12
1097 } -
1098 -
1099 // Pick the first host address candidate -
1100 host = addresses.takeFirst();
executed (the execution status of this line is deduced): host = addresses.takeFirst();
-
1101#if defined(QABSTRACTSOCKET_DEBUG) -
1102 qDebug("QAbstractSocketPrivate::_q_connectToNextAddress(), connecting to %s:%i, %d left to try", -
1103 host.toString().toLatin1().constData(), port, addresses.count()); -
1104#endif -
1105 -
1106 if (!initSocketLayer(host.protocol())) {
partially evaluated: !initSocketLayer(host.protocol())
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2102
0-2102
1107 // hope that the next address is better -
1108#if defined(QABSTRACTSOCKET_DEBUG) -
1109 qDebug("QAbstractSocketPrivate::_q_connectToNextAddress(), failed to initialize sock layer"); -
1110#endif -
1111 continue;
never executed: continue;
0
1112 } -
1113 -
1114 // Tries to connect to the address. If it succeeds immediately -
1115 // (localhost address on BSD or any UDP connect), emit -
1116 // connected() and return. -
1117 if (socketEngine->connectToHost(host, port)) {
evaluated: socketEngine->connectToHost(host, port)
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:2096
6-2096
1118 //_q_testConnection(); -
1119 fetchConnectionParameters();
executed (the execution status of this line is deduced): fetchConnectionParameters();
-
1120 return;
executed: return;
Execution Count:6
6
1121 } -
1122 -
1123 // cache the socket descriptor even if we're not fully connected yet -
1124 cachedSocketDescriptor = socketEngine->socketDescriptor();
executed (the execution status of this line is deduced): cachedSocketDescriptor = socketEngine->socketDescriptor();
-
1125 -
1126 // Check that we're in delayed connection state. If not, try -
1127 // the next address -
1128 if (socketEngine->state() != QAbstractSocket::ConnectingState) {
evaluated: socketEngine->state() != QAbstractSocket::ConnectingState
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2094
2-2094
1129#if defined(QABSTRACTSOCKET_DEBUG) -
1130 qDebug("QAbstractSocketPrivate::_q_connectToNextAddress(), connection failed (%s)", -
1131 socketEngine->errorString().toLatin1().constData()); -
1132#endif -
1133 continue;
executed: continue;
Execution Count:2
2
1134 } -
1135 -
1136 // Start the connect timer. -
1137 if (threadData->eventDispatcher) {
partially evaluated: threadData->eventDispatcher
TRUEFALSE
yes
Evaluation Count:2094
no
Evaluation Count:0
0-2094
1138 if (!connectTimer) {
evaluated: !connectTimer
TRUEFALSE
yes
Evaluation Count:1956
yes
Evaluation Count:138
138-1956
1139 connectTimer = new QTimer(q);
executed (the execution status of this line is deduced): connectTimer = new QTimer(q);
-
1140 QObject::connect(connectTimer, SIGNAL(timeout()),
executed (the execution status of this line is deduced): QObject::connect(connectTimer, "2""timeout()",
-
1141 q, SLOT(_q_abortConnectionAttempt()),
executed (the execution status of this line is deduced): q, "1""_q_abortConnectionAttempt()",
-
1142 Qt::DirectConnection);
executed (the execution status of this line is deduced): Qt::DirectConnection);
-
1143 }
executed: }
Execution Count:1956
1956
1144 connectTimer->start(QT_CONNECT_TIMEOUT);
executed (the execution status of this line is deduced): connectTimer->start(30000);
-
1145 }
executed: }
Execution Count:2094
2094
1146 -
1147 // Wait for a write notification that will eventually call -
1148 // _q_testConnection(). -
1149 socketEngine->setWriteNotificationEnabled(true);
executed (the execution status of this line is deduced): socketEngine->setWriteNotificationEnabled(true);
-
1150 break;
executed: break;
Execution Count:2094
2094
1151 } while (state != QAbstractSocket::ConnectedState);
partially evaluated: state != QAbstractSocket::ConnectedState
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
1152}
executed: }
Execution Count:2094
2094
1153 -
1154/*! \internal -
1155 -
1156 Tests if a connection has been established. If it has, connected() -
1157 is emitted. Otherwise, _q_connectToNextAddress() is invoked. -
1158*/ -
1159void QAbstractSocketPrivate::_q_testConnection() -
1160{ -
1161 if (socketEngine) {
partially evaluated: socketEngine
TRUEFALSE
yes
Evaluation Count:1261
no
Evaluation Count:0
0-1261
1162 if (threadData->eventDispatcher) {
partially evaluated: threadData->eventDispatcher
TRUEFALSE
yes
Evaluation Count:1261
no
Evaluation Count:0
0-1261
1163 if (connectTimer)
evaluated: connectTimer
TRUEFALSE
yes
Evaluation Count:1202
yes
Evaluation Count:59
59-1202
1164 connectTimer->stop();
executed: connectTimer->stop();
Execution Count:1202
1202
1165 }
executed: }
Execution Count:1261
1261
1166 -
1167 if (socketEngine->state() == QAbstractSocket::ConnectedState) {
evaluated: socketEngine->state() == QAbstractSocket::ConnectedState
TRUEFALSE
yes
Evaluation Count:1246
yes
Evaluation Count:15
15-1246
1168 // Fetch the parameters if our connection is completed; -
1169 // otherwise, fall out and try the next address. -
1170 fetchConnectionParameters();
executed (the execution status of this line is deduced): fetchConnectionParameters();
-
1171 if (pendingClose) {
partially evaluated: pendingClose
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1246
0-1246
1172 q_func()->disconnectFromHost();
never executed (the execution status of this line is deduced): q_func()->disconnectFromHost();
-
1173 pendingClose = false;
never executed (the execution status of this line is deduced): pendingClose = false;
-
1174 }
never executed: }
0
1175 return;
executed: return;
Execution Count:1246
1246
1176 } -
1177 -
1178 // don't retry the other addresses if we had a proxy error -
1179 if (isProxyError(socketEngine->error()))
evaluated: isProxyError(socketEngine->error())
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:10
5-10
1180 addresses.clear();
executed: addresses.clear();
Execution Count:5
5
1181 }
executed: }
Execution Count:15
15
1182 -
1183 if (threadData->eventDispatcher) {
partially evaluated: threadData->eventDispatcher
TRUEFALSE
yes
Evaluation Count:15
no
Evaluation Count:0
0-15
1184 if (connectTimer)
evaluated: connectTimer
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:7
7-8
1185 connectTimer->stop();
executed: connectTimer->stop();
Execution Count:8
8
1186 }
executed: }
Execution Count:15
15
1187 -
1188#if defined(QABSTRACTSOCKET_DEBUG) -
1189 qDebug("QAbstractSocketPrivate::_q_testConnection() connection failed," -
1190 " checking for alternative addresses"); -
1191#endif -
1192 _q_connectToNextAddress();
executed (the execution status of this line is deduced): _q_connectToNextAddress();
-
1193}
executed: }
Execution Count:15
15
1194 -
1195/*! \internal -
1196 -
1197 This function is called after a certain number of seconds has -
1198 passed while waiting for a connection. It simply tests the -
1199 connection, and continues to the next address if the connection -
1200 failed. -
1201*/ -
1202void QAbstractSocketPrivate::_q_abortConnectionAttempt() -
1203{ -
1204 Q_Q(QAbstractSocket);
never executed (the execution status of this line is deduced): QAbstractSocket * const q = q_func();
-
1205#if defined(QABSTRACTSOCKET_DEBUG) -
1206 qDebug("QAbstractSocketPrivate::_q_abortConnectionAttempt() (timed out)"); -
1207#endif -
1208 if (socketEngine)
never evaluated: socketEngine
0
1209 socketEngine->setWriteNotificationEnabled(false);
never executed: socketEngine->setWriteNotificationEnabled(false);
0
1210 -
1211 connectTimer->stop();
never executed (the execution status of this line is deduced): connectTimer->stop();
-
1212 -
1213 if (addresses.isEmpty()) {
never evaluated: addresses.isEmpty()
0
1214 state = QAbstractSocket::UnconnectedState;
never executed (the execution status of this line is deduced): state = QAbstractSocket::UnconnectedState;
-
1215 socketError = QAbstractSocket::SocketTimeoutError;
never executed (the execution status of this line is deduced): socketError = QAbstractSocket::SocketTimeoutError;
-
1216 q->setErrorString(QAbstractSocket::tr("Connection timed out"));
never executed (the execution status of this line is deduced): q->setErrorString(QAbstractSocket::tr("Connection timed out"));
-
1217 emit q->stateChanged(state);
never executed (the execution status of this line is deduced): q->stateChanged(state);
-
1218 emit q->error(socketError);
never executed (the execution status of this line is deduced): q->error(socketError);
-
1219 } else {
never executed: }
0
1220 _q_connectToNextAddress();
never executed (the execution status of this line is deduced): _q_connectToNextAddress();
-
1221 }
never executed: }
0
1222} -
1223 -
1224void QAbstractSocketPrivate::_q_forceDisconnect() -
1225{ -
1226 Q_Q(QAbstractSocket);
never executed (the execution status of this line is deduced): QAbstractSocket * const q = q_func();
-
1227 if (socketEngine && socketEngine->isValid() && state == QAbstractSocket::ClosingState) {
never evaluated: socketEngine
never evaluated: socketEngine->isValid()
never evaluated: state == QAbstractSocket::ClosingState
0
1228 socketEngine->close();
never executed (the execution status of this line is deduced): socketEngine->close();
-
1229 q->disconnectFromHost();
never executed (the execution status of this line is deduced): q->disconnectFromHost();
-
1230 }
never executed: }
0
1231}
never executed: }
0
1232 -
1233/*! \internal -
1234 -
1235 Reads data from the socket layer into the read buffer. Returns -
1236 true on success; otherwise false. -
1237*/ -
1238bool QAbstractSocketPrivate::readFromSocket() -
1239{ -
1240 Q_Q(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocket * const q = q_func();
-
1241 // Find how many bytes we can read from the socket layer. -
1242 qint64 bytesToRead = socketEngine->bytesAvailable();
executed (the execution status of this line is deduced): qint64 bytesToRead = socketEngine->bytesAvailable();
-
1243 if (bytesToRead == 0) {
evaluated: bytesToRead == 0
TRUEFALSE
yes
Evaluation Count:205
yes
Evaluation Count:15869
205-15869
1244 // Under heavy load, certain conditions can trigger read notifications -
1245 // for socket notifiers on which there is no activity. If we continue -
1246 // to read 0 bytes from the socket, we will trigger behavior similar -
1247 // to that which signals a remote close. When we hit this condition, -
1248 // we try to read 4k of data from the socket, which will give us either -
1249 // an EAGAIN/EWOULDBLOCK if the connection is alive (i.e., the remote -
1250 // host has _not_ disappeared). -
1251 bytesToRead = 4096;
executed (the execution status of this line is deduced): bytesToRead = 4096;
-
1252 }
executed: }
Execution Count:205
205
1253 if (readBufferMaxSize && bytesToRead > (readBufferMaxSize - buffer.size()))
evaluated: readBufferMaxSize
TRUEFALSE
yes
Evaluation Count:1174
yes
Evaluation Count:14900
evaluated: bytesToRead > (readBufferMaxSize - buffer.size())
TRUEFALSE
yes
Evaluation Count:36
yes
Evaluation Count:1138
36-14900
1254 bytesToRead = readBufferMaxSize - buffer.size();
executed: bytesToRead = readBufferMaxSize - buffer.size();
Execution Count:36
36
1255 -
1256#if defined(QABSTRACTSOCKET_DEBUG) -
1257 qDebug("QAbstractSocketPrivate::readFromSocket() about to read %d bytes", -
1258 int(bytesToRead)); -
1259#endif -
1260 -
1261 // Read from the socket, store data in the read buffer. -
1262 char *ptr = buffer.reserve(bytesToRead);
executed (the execution status of this line is deduced): char *ptr = buffer.reserve(bytesToRead);
-
1263 qint64 readBytes = socketEngine->read(ptr, bytesToRead);
executed (the execution status of this line is deduced): qint64 readBytes = socketEngine->read(ptr, bytesToRead);
-
1264 if (readBytes == -2) {
partially evaluated: readBytes == -2
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:16074
0-16074
1265 // No bytes currently available for reading. -
1266 buffer.chop(bytesToRead);
never executed (the execution status of this line is deduced): buffer.chop(bytesToRead);
-
1267 return true;
never executed: return true;
0
1268 } -
1269 buffer.chop(int(bytesToRead - (readBytes < 0 ? qint64(0) : readBytes)));
executed (the execution status of this line is deduced): buffer.chop(int(bytesToRead - (readBytes < 0 ? qint64(0) : readBytes)));
-
1270#if defined(QABSTRACTSOCKET_DEBUG) -
1271 qDebug("QAbstractSocketPrivate::readFromSocket() got %d bytes, buffer size = %d", -
1272 int(readBytes), buffer.size()); -
1273#endif -
1274 -
1275 if (!socketEngine->isValid()) {
evaluated: !socketEngine->isValid()
TRUEFALSE
yes
Evaluation Count:205
yes
Evaluation Count:15869
205-15869
1276 socketError = socketEngine->error();
executed (the execution status of this line is deduced): socketError = socketEngine->error();
-
1277 q->setErrorString(socketEngine->errorString());
executed (the execution status of this line is deduced): q->setErrorString(socketEngine->errorString());
-
1278 emit q->error(socketError);
executed (the execution status of this line is deduced): q->error(socketError);
-
1279#if defined(QABSTRACTSOCKET_DEBUG) -
1280 qDebug("QAbstractSocketPrivate::readFromSocket() read failed: %s", -
1281 q->errorString().toLatin1().constData()); -
1282#endif -
1283 resetSocketLayer();
executed (the execution status of this line is deduced): resetSocketLayer();
-
1284 return false;
executed: return false;
Execution Count:205
205
1285 } -
1286 -
1287 return true;
executed: return true;
Execution Count:15869
15869
1288} -
1289 -
1290/*! \internal -
1291 -
1292 Sets up the internal state after the connection has succeeded. -
1293*/ -
1294void QAbstractSocketPrivate::fetchConnectionParameters() -
1295{ -
1296 Q_Q(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocket * const q = q_func();
-
1297 -
1298 peerName = hostName;
executed (the execution status of this line is deduced): peerName = hostName;
-
1299 if (socketEngine) {
partially evaluated: socketEngine
TRUEFALSE
yes
Evaluation Count:1252
no
Evaluation Count:0
0-1252
1300 socketEngine->setReadNotificationEnabled(true);
executed (the execution status of this line is deduced): socketEngine->setReadNotificationEnabled(true);
-
1301 socketEngine->setWriteNotificationEnabled(true);
executed (the execution status of this line is deduced): socketEngine->setWriteNotificationEnabled(true);
-
1302 localPort = socketEngine->localPort();
executed (the execution status of this line is deduced): localPort = socketEngine->localPort();
-
1303 peerPort = socketEngine->peerPort();
executed (the execution status of this line is deduced): peerPort = socketEngine->peerPort();
-
1304 localAddress = socketEngine->localAddress();
executed (the execution status of this line is deduced): localAddress = socketEngine->localAddress();
-
1305 peerAddress = socketEngine->peerAddress();
executed (the execution status of this line is deduced): peerAddress = socketEngine->peerAddress();
-
1306 cachedSocketDescriptor = socketEngine->socketDescriptor();
executed (the execution status of this line is deduced): cachedSocketDescriptor = socketEngine->socketDescriptor();
-
1307 }
executed: }
Execution Count:1252
1252
1308 -
1309 state = QAbstractSocket::ConnectedState;
executed (the execution status of this line is deduced): state = QAbstractSocket::ConnectedState;
-
1310 emit q->stateChanged(state);
executed (the execution status of this line is deduced): q->stateChanged(state);
-
1311 emit q->connected();
executed (the execution status of this line is deduced): q->connected();
-
1312 -
1313#if defined(QABSTRACTSOCKET_DEBUG) -
1314 qDebug("QAbstractSocketPrivate::fetchConnectionParameters() connection to %s:%i established", -
1315 host.toString().toLatin1().constData(), port); -
1316#endif -
1317}
executed: }
Execution Count:1252
1252
1318 -
1319 -
1320void QAbstractSocketPrivate::pauseSocketNotifiers(QAbstractSocket *socket) -
1321{ -
1322 QAbstractSocketEngine *socketEngine = socket->d_func()->socketEngine;
executed (the execution status of this line is deduced): QAbstractSocketEngine *socketEngine = socket->d_func()->socketEngine;
-
1323 if (!socketEngine)
evaluated: !socketEngine
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:251
2-251
1324 return;
executed: return;
Execution Count:2
2
1325 socket->d_func()->prePauseReadSocketNotifierState = socketEngine->isReadNotificationEnabled();
executed (the execution status of this line is deduced): socket->d_func()->prePauseReadSocketNotifierState = socketEngine->isReadNotificationEnabled();
-
1326 socket->d_func()->prePauseWriteSocketNotifierState = socketEngine->isWriteNotificationEnabled();
executed (the execution status of this line is deduced): socket->d_func()->prePauseWriteSocketNotifierState = socketEngine->isWriteNotificationEnabled();
-
1327 socket->d_func()->prePauseExceptionSocketNotifierState = socketEngine->isExceptionNotificationEnabled();
executed (the execution status of this line is deduced): socket->d_func()->prePauseExceptionSocketNotifierState = socketEngine->isExceptionNotificationEnabled();
-
1328 socketEngine->setReadNotificationEnabled(false);
executed (the execution status of this line is deduced): socketEngine->setReadNotificationEnabled(false);
-
1329 socketEngine->setWriteNotificationEnabled(false);
executed (the execution status of this line is deduced): socketEngine->setWriteNotificationEnabled(false);
-
1330 socketEngine->setExceptionNotificationEnabled(false);
executed (the execution status of this line is deduced): socketEngine->setExceptionNotificationEnabled(false);
-
1331}
executed: }
Execution Count:251
251
1332 -
1333void QAbstractSocketPrivate::resumeSocketNotifiers(QAbstractSocket *socket) -
1334{ -
1335 QAbstractSocketEngine *socketEngine = socket->d_func()->socketEngine;
executed (the execution status of this line is deduced): QAbstractSocketEngine *socketEngine = socket->d_func()->socketEngine;
-
1336 if (!socketEngine)
evaluated: !socketEngine
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:251
2-251
1337 return;
executed: return;
Execution Count:2
2
1338 socketEngine->setReadNotificationEnabled(socket->d_func()->prePauseReadSocketNotifierState);
executed (the execution status of this line is deduced): socketEngine->setReadNotificationEnabled(socket->d_func()->prePauseReadSocketNotifierState);
-
1339 socketEngine->setWriteNotificationEnabled(socket->d_func()->prePauseWriteSocketNotifierState);
executed (the execution status of this line is deduced): socketEngine->setWriteNotificationEnabled(socket->d_func()->prePauseWriteSocketNotifierState);
-
1340 socketEngine->setExceptionNotificationEnabled(socket->d_func()->prePauseExceptionSocketNotifierState);
executed (the execution status of this line is deduced): socketEngine->setExceptionNotificationEnabled(socket->d_func()->prePauseExceptionSocketNotifierState);
-
1341}
executed: }
Execution Count:251
251
1342 -
1343QAbstractSocketEngine* QAbstractSocketPrivate::getSocketEngine(QAbstractSocket *socket) -
1344{ -
1345 return socket->d_func()->socketEngine;
never executed: return socket->d_func()->socketEngine;
0
1346} -
1347 -
1348 -
1349/*! \internal -
1350 -
1351 Constructs a new abstract socket of type \a socketType. The \a -
1352 parent argument is passed to QObject's constructor. -
1353*/ -
1354QAbstractSocket::QAbstractSocket(SocketType socketType, -
1355 QAbstractSocketPrivate &dd, QObject *parent) -
1356 : QIODevice(dd, parent) -
1357{ -
1358 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
1359#if defined(QABSTRACTSOCKET_DEBUG) -
1360 qDebug("QAbstractSocket::QAbstractSocket(%sSocket, QAbstractSocketPrivate == %p, parent == %p)", -
1361 socketType == TcpSocket ? "Tcp" : socketType == UdpSocket -
1362 ? "Udp" : "Unknown", &dd, parent); -
1363#endif -
1364 d->socketType = socketType;
executed (the execution status of this line is deduced): d->socketType = socketType;
-
1365}
executed: }
Execution Count:3144
3144
1366 -
1367/*! -
1368 Creates a new abstract socket of type \a socketType. The \a -
1369 parent argument is passed to QObject's constructor. -
1370 -
1371 \sa socketType(), QTcpSocket, QUdpSocket -
1372*/ -
1373QAbstractSocket::QAbstractSocket(SocketType socketType, QObject *parent) -
1374 : QIODevice(*new QAbstractSocketPrivate, parent) -
1375{ -
1376 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
1377#if defined(QABSTRACTSOCKET_DEBUG) -
1378 qDebug("QAbstractSocket::QAbstractSocket(%p)", parent); -
1379#endif -
1380 d->socketType = socketType;
executed (the execution status of this line is deduced): d->socketType = socketType;
-
1381}
executed: }
Execution Count:1
1
1382 -
1383/*! -
1384 Destroys the socket. -
1385*/ -
1386QAbstractSocket::~QAbstractSocket() -
1387{ -
1388 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
1389#if defined(QABSTRACTSOCKET_DEBUG) -
1390 qDebug("QAbstractSocket::~QAbstractSocket()"); -
1391#endif -
1392 if (d->state != UnconnectedState)
evaluated: d->state != UnconnectedState
TRUEFALSE
yes
Evaluation Count:1629
yes
Evaluation Count:1513
1513-1629
1393 abort();
executed: abort();
Execution Count:1629
1629
1394}
executed: }
Execution Count:3142
3142
1395 -
1396/*! -
1397 \since 5.0 -
1398 -
1399 Continues data transfer on the socket. This method should only be used -
1400 after the socket has been set to pause upon notifications and a -
1401 notification has been received. -
1402 The only notification currently supported is QSslSocket::sslErrors(). -
1403 Calling this method if the socket is not paused results in undefined -
1404 behavior. -
1405 -
1406 \sa pauseMode(), setPauseMode() -
1407*/ -
1408void QAbstractSocket::resume() -
1409{ -
1410 QAbstractSocketPrivate::resumeSocketNotifiers(this);
never executed (the execution status of this line is deduced): QAbstractSocketPrivate::resumeSocketNotifiers(this);
-
1411}
never executed: }
0
1412 -
1413/*! -
1414 \since 5.0 -
1415 -
1416 Returns the pause mode of this socket. -
1417 -
1418 \sa setPauseMode(), resume() -
1419*/ -
1420QAbstractSocket::PauseModes QAbstractSocket::pauseMode() const -
1421{ -
1422 return d_func()->pauseMode;
executed: return d_func()->pauseMode;
Execution Count:9
9
1423} -
1424 -
1425 -
1426/*! -
1427 \since 5.0 -
1428 -
1429 Controls whether to pause upon receiving a notification. The \a pauseMode parameter -
1430 specifies the conditions in which the socket should be paused. The only notification -
1431 currently supported is QSslSocket::sslErrors(). If set to PauseOnSslErrors, -
1432 data transfer on the socket will be paused and needs to be enabled explicitly -
1433 again by calling resume(). -
1434 By default this option is set to PauseNever. -
1435 This option must be called before connecting to the server, otherwise it will -
1436 result in undefined behavior. -
1437 -
1438 \sa pauseMode(), resume() -
1439*/ -
1440void QAbstractSocket::setPauseMode(PauseModes pauseMode) -
1441{ -
1442 d_func()->pauseMode = pauseMode;
never executed (the execution status of this line is deduced): d_func()->pauseMode = pauseMode;
-
1443}
never executed: }
0
1444 -
1445/*! -
1446 \since 5.0 -
1447 -
1448 Binds to \a address on port \a port, using the BindMode \a mode. -
1449 -
1450 Binds this socket to the address \a address and the port \a port. -
1451 -
1452 For UDP sockets, after binding, the signal QUdpSocket::readyRead() is emitted -
1453 whenever a UDP datagram arrives on the specified address and port. -
1454 Thus, This function is useful to write UDP servers. -
1455 -
1456 For TCP sockets, this function may be used to specify which interface to use -
1457 for an outgoing connection, which is useful in case of multiple network -
1458 interfaces. -
1459 -
1460 By default, the socket is bound using the DefaultForPlatform BindMode. -
1461 If a port is not specified, a random port is chosen. -
1462 -
1463 On success, the functions returns true and the socket enters -
1464 BoundState; otherwise it returns false. -
1465 -
1466*/ -
1467bool QAbstractSocket::bind(const QHostAddress &address, quint16 port, BindMode mode) -
1468{ -
1469 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
1470 -
1471 // now check if the socket engine is initialized and to the right type -
1472 if (!d->socketEngine || !d->socketEngine->isValid()) {
evaluated: !d->socketEngine
TRUEFALSE
yes
Evaluation Count:286
yes
Evaluation Count:19
partially evaluated: !d->socketEngine->isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:19
0-286
1473 QHostAddress nullAddress;
executed (the execution status of this line is deduced): QHostAddress nullAddress;
-
1474 d->resolveProxy(nullAddress.toString(), port);
executed (the execution status of this line is deduced): d->resolveProxy(nullAddress.toString(), port);
-
1475 -
1476 QAbstractSocket::NetworkLayerProtocol protocol = address.protocol();
executed (the execution status of this line is deduced): QAbstractSocket::NetworkLayerProtocol protocol = address.protocol();
-
1477 if (protocol == QAbstractSocket::UnknownNetworkLayerProtocol)
partially evaluated: protocol == QAbstractSocket::UnknownNetworkLayerProtocol
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:286
0-286
1478 protocol = nullAddress.protocol();
never executed: protocol = nullAddress.protocol();
0
1479 -
1480 if (!d->initSocketLayer(protocol))
partially evaluated: !d->initSocketLayer(protocol)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:286
0-286
1481 return false;
never executed: return false;
0
1482 }
executed: }
Execution Count:286
286
1483 -
1484 if (mode != DefaultForPlatform) {
evaluated: mode != DefaultForPlatform
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:302
3-302
1485#ifdef Q_OS_UNIX -
1486 if ((mode & ShareAddress) || (mode & ReuseAddressHint))
evaluated: (mode & ShareAddress)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
partially evaluated: (mode & ReuseAddressHint)
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
1487 d->socketEngine->setOption(QAbstractSocketEngine::AddressReusable, 1);
executed: d->socketEngine->setOption(QAbstractSocketEngine::AddressReusable, 1);
Execution Count:3
3
1488 else -
1489 d->socketEngine->setOption(QAbstractSocketEngine::AddressReusable, 0);
never executed: d->socketEngine->setOption(QAbstractSocketEngine::AddressReusable, 0);
0
1490#endif -
1491#ifdef Q_OS_WIN -
1492 if (mode & ReuseAddressHint) -
1493 d->socketEngine->setOption(QAbstractSocketEngine::AddressReusable, 1); -
1494 else -
1495 d->socketEngine->setOption(QAbstractSocketEngine::AddressReusable, 0); -
1496 if (mode & DontShareAddress) -
1497 d->socketEngine->setOption(QAbstractSocketEngine::BindExclusively, 1); -
1498 else -
1499 d->socketEngine->setOption(QAbstractSocketEngine::BindExclusively, 0); -
1500#endif -
1501 } -
1502 bool result = d->socketEngine->bind(address, port);
executed (the execution status of this line is deduced): bool result = d->socketEngine->bind(address, port);
-
1503 d->cachedSocketDescriptor = d->socketEngine->socketDescriptor();
executed (the execution status of this line is deduced): d->cachedSocketDescriptor = d->socketEngine->socketDescriptor();
-
1504 -
1505 if (!result) {
evaluated: !result
TRUEFALSE
yes
Evaluation Count:27
yes
Evaluation Count:278
27-278
1506 d->socketError = d->socketEngine->error();
executed (the execution status of this line is deduced): d->socketError = d->socketEngine->error();
-
1507 setErrorString(d->socketEngine->errorString());
executed (the execution status of this line is deduced): setErrorString(d->socketEngine->errorString());
-
1508 emit error(d->socketError);
executed (the execution status of this line is deduced): error(d->socketError);
-
1509 return false;
executed: return false;
Execution Count:27
27
1510 } -
1511 -
1512 d->state = BoundState;
executed (the execution status of this line is deduced): d->state = BoundState;
-
1513 d->localAddress = d->socketEngine->localAddress();
executed (the execution status of this line is deduced): d->localAddress = d->socketEngine->localAddress();
-
1514 d->localPort = d->socketEngine->localPort();
executed (the execution status of this line is deduced): d->localPort = d->socketEngine->localPort();
-
1515 -
1516 emit stateChanged(d->state);
executed (the execution status of this line is deduced): stateChanged(d->state);
-
1517 d->socketEngine->setReadNotificationEnabled(true);
executed (the execution status of this line is deduced): d->socketEngine->setReadNotificationEnabled(true);
-
1518 return true;
executed: return true;
Execution Count:278
278
1519} -
1520 -
1521/*! -
1522 \since 5.0 -
1523 \overload -
1524 -
1525 Binds to QHostAddress:Any on port \a port, using the BindMode \a mode. -
1526 -
1527 By default, the socket is bound using the DefaultForPlatform BindMode. -
1528 If a port is not specified, a random port is chosen. -
1529*/ -
1530bool QAbstractSocket::bind(quint16 port, BindMode mode) -
1531{ -
1532 return bind(QHostAddress::Any, port, mode);
executed: return bind(QHostAddress::Any, port, mode);
Execution Count:121
121
1533} -
1534 -
1535/*! -
1536 Returns true if the socket is valid and ready for use; otherwise -
1537 returns false. -
1538 -
1539 \b{Note:} The socket's state must be ConnectedState before reading and -
1540 writing can occur. -
1541 -
1542 \sa state() -
1543*/ -
1544bool QAbstractSocket::isValid() const -
1545{ -
1546 return d_func()->socketEngine ? d_func()->socketEngine->isValid() : isOpen();
executed: return d_func()->socketEngine ? d_func()->socketEngine->isValid() : isOpen();
Execution Count:3341915
3341915
1547} -
1548 -
1549/*! -
1550 Attempts to make a connection to \a hostName on the given \a port. -
1551 The \a protocol parameter can be used to specify which network -
1552 protocol to use (eg. IPv4 or IPv6). -
1553 -
1554 The socket is opened in the given \a openMode and first enters -
1555 HostLookupState, then performs a host name lookup of \a hostName. -
1556 If the lookup succeeds, hostFound() is emitted and QAbstractSocket -
1557 enters ConnectingState. It then attempts to connect to the address -
1558 or addresses returned by the lookup. Finally, if a connection is -
1559 established, QAbstractSocket enters ConnectedState and -
1560 emits connected(). -
1561 -
1562 At any point, the socket can emit error() to signal that an error -
1563 occurred. -
1564 -
1565 \a hostName may be an IP address in string form (e.g., -
1566 "43.195.83.32"), or it may be a host name (e.g., -
1567 "example.com"). QAbstractSocket will do a lookup only if -
1568 required. \a port is in native byte order. -
1569 -
1570 \sa state(), peerName(), peerAddress(), peerPort(), waitForConnected() -
1571*/ -
1572void QAbstractSocket::connectToHost(const QString &hostName, quint16 port, -
1573 OpenMode openMode, -
1574 NetworkLayerProtocol protocol) -
1575{ -
1576 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
1577#if defined(QABSTRACTSOCKET_DEBUG) -
1578 qDebug("QAbstractSocket::connectToHost(\"%s\", %i, %i)...", qPrintable(hostName), port, -
1579 (int) openMode); -
1580#endif -
1581 -
1582 if (d->state == ConnectedState || d->state == ConnectingState
partially evaluated: d->state == ConnectedState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2277
partially evaluated: d->state == ConnectingState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2277
0-2277
1583 || d->state == ClosingState || d->state == HostLookupState) {
partially evaluated: d->state == ClosingState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2277
partially evaluated: d->state == HostLookupState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2277
0-2277
1584 qWarning("QAbstractSocket::connectToHost() called when already looking up or connecting/connected to \"%s\"", qPrintable(hostName));
never executed (the execution status of this line is deduced): QMessageLogger("socket/qabstractsocket.cpp", 1584, __PRETTY_FUNCTION__).warning("QAbstractSocket::connectToHost() called when already looking up or connecting/connected to \"%s\"", QString(hostName).toLocal8Bit().constData());
-
1585 d->socketError = QAbstractSocket::OperationError;
never executed (the execution status of this line is deduced): d->socketError = QAbstractSocket::OperationError;
-
1586 setErrorString(QAbstractSocket::tr("Trying to connect while connection is in progress"));
never executed (the execution status of this line is deduced): setErrorString(QAbstractSocket::tr("Trying to connect while connection is in progress"));
-
1587 emit error(d->socketError);
never executed (the execution status of this line is deduced): error(d->socketError);
-
1588 return;
never executed: return;
0
1589 } -
1590 -
1591 d->preferredNetworkLayerProtocol = protocol;
executed (the execution status of this line is deduced): d->preferredNetworkLayerProtocol = protocol;
-
1592 d->hostName = hostName;
executed (the execution status of this line is deduced): d->hostName = hostName;
-
1593 d->port = port;
executed (the execution status of this line is deduced): d->port = port;
-
1594 d->state = UnconnectedState;
executed (the execution status of this line is deduced): d->state = UnconnectedState;
-
1595 d->buffer.clear();
executed (the execution status of this line is deduced): d->buffer.clear();
-
1596 d->writeBuffer.clear();
executed (the execution status of this line is deduced): d->writeBuffer.clear();
-
1597 d->abortCalled = false;
executed (the execution status of this line is deduced): d->abortCalled = false;
-
1598 d->closeCalled = false;
executed (the execution status of this line is deduced): d->closeCalled = false;
-
1599 d->pendingClose = false;
executed (the execution status of this line is deduced): d->pendingClose = false;
-
1600 d->localPort = 0;
executed (the execution status of this line is deduced): d->localPort = 0;
-
1601 d->peerPort = 0;
executed (the execution status of this line is deduced): d->peerPort = 0;
-
1602 d->localAddress.clear();
executed (the execution status of this line is deduced): d->localAddress.clear();
-
1603 d->peerAddress.clear();
executed (the execution status of this line is deduced): d->peerAddress.clear();
-
1604 d->peerName = hostName;
executed (the execution status of this line is deduced): d->peerName = hostName;
-
1605 if (d->hostLookupId != -1) {
partially evaluated: d->hostLookupId != -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2277
0-2277
1606 QHostInfo::abortHostLookup(d->hostLookupId);
never executed (the execution status of this line is deduced): QHostInfo::abortHostLookup(d->hostLookupId);
-
1607 d->hostLookupId = -1;
never executed (the execution status of this line is deduced): d->hostLookupId = -1;
-
1608 }
never executed: }
0
1609 -
1610#ifndef QT_NO_NETWORKPROXY -
1611 // Get the proxy information -
1612 d->resolveProxy(hostName, port);
executed (the execution status of this line is deduced): d->resolveProxy(hostName, port);
-
1613 if (d->proxyInUse.type() == QNetworkProxy::DefaultProxy) {
partially evaluated: d->proxyInUse.type() == QNetworkProxy::DefaultProxy
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2277
0-2277
1614 // failed to setup the proxy -
1615 d->socketError = QAbstractSocket::UnsupportedSocketOperationError;
never executed (the execution status of this line is deduced): d->socketError = QAbstractSocket::UnsupportedSocketOperationError;
-
1616 setErrorString(QAbstractSocket::tr("Operation on socket is not supported"));
never executed (the execution status of this line is deduced): setErrorString(QAbstractSocket::tr("Operation on socket is not supported"));
-
1617 emit error(d->socketError);
never executed (the execution status of this line is deduced): error(d->socketError);
-
1618 return;
never executed: return;
0
1619 } -
1620#endif -
1621 -
1622 if (openMode & QIODevice::Unbuffered)
evaluated: openMode & QIODevice::Unbuffered
TRUEFALSE
yes
Evaluation Count:425
yes
Evaluation Count:1852
425-1852
1623 d->isBuffered = false; // Unbuffered QTcpSocket
executed: d->isBuffered = false;
Execution Count:425
425
1624 else if (!d_func()->isBuffered)
evaluated: !d_func()->isBuffered
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:1846
6-1846
1625 openMode |= QAbstractSocket::Unbuffered; // QUdpSocket
executed: openMode |= QAbstractSocket::Unbuffered;
Execution Count:6
6
1626 -
1627 QIODevice::open(openMode);
executed (the execution status of this line is deduced): QIODevice::open(openMode);
-
1628 d->state = HostLookupState;
executed (the execution status of this line is deduced): d->state = HostLookupState;
-
1629 emit stateChanged(d->state);
executed (the execution status of this line is deduced): stateChanged(d->state);
-
1630 -
1631 QHostAddress temp;
executed (the execution status of this line is deduced): QHostAddress temp;
-
1632 if (temp.setAddress(hostName)) {
evaluated: temp.setAddress(hostName)
TRUEFALSE
yes
Evaluation Count:519
yes
Evaluation Count:1758
519-1758
1633 QHostInfo info;
executed (the execution status of this line is deduced): QHostInfo info;
-
1634 info.setAddresses(QList<QHostAddress>() << temp);
executed (the execution status of this line is deduced): info.setAddresses(QList<QHostAddress>() << temp);
-
1635 d->_q_startConnecting(info);
executed (the execution status of this line is deduced): d->_q_startConnecting(info);
-
1636#ifndef QT_NO_NETWORKPROXY -
1637 } else if (d->proxyInUse.capabilities() & QNetworkProxy::HostNameLookupCapability) {
executed: }
Execution Count:519
evaluated: d->proxyInUse.capabilities() & QNetworkProxy::HostNameLookupCapability
TRUEFALSE
yes
Evaluation Count:59
yes
Evaluation Count:1699
59-1699
1638 // the proxy supports connection by name, so use it -
1639 d->startConnectingByName(hostName);
executed (the execution status of this line is deduced): d->startConnectingByName(hostName);
-
1640 return;
executed: return;
Execution Count:59
59
1641#endif -
1642 } else { -
1643 if (d->threadData->eventDispatcher) {
partially evaluated: d->threadData->eventDispatcher
TRUEFALSE
yes
Evaluation Count:1699
no
Evaluation Count:0
0-1699
1644 // this internal API for QHostInfo either immediately gives us the desired -
1645 // QHostInfo from cache or later calls the _q_startConnecting slot. -
1646 bool immediateResultValid = false;
executed (the execution status of this line is deduced): bool immediateResultValid = false;
-
1647 QHostInfo hostInfo = qt_qhostinfo_lookup(hostName,
executed (the execution status of this line is deduced): QHostInfo hostInfo = qt_qhostinfo_lookup(hostName,
-
1648 this,
executed (the execution status of this line is deduced): this,
-
1649 SLOT(_q_startConnecting(QHostInfo)),
executed (the execution status of this line is deduced): "1""_q_startConnecting(QHostInfo)",
-
1650 &immediateResultValid,
executed (the execution status of this line is deduced): &immediateResultValid,
-
1651 &d->hostLookupId);
executed (the execution status of this line is deduced): &d->hostLookupId);
-
1652 if (immediateResultValid) {
evaluated: immediateResultValid
TRUEFALSE
yes
Evaluation Count:1577
yes
Evaluation Count:122
122-1577
1653 d->hostLookupId = -1;
executed (the execution status of this line is deduced): d->hostLookupId = -1;
-
1654 d->_q_startConnecting(hostInfo);
executed (the execution status of this line is deduced): d->_q_startConnecting(hostInfo);
-
1655 }
executed: }
Execution Count:1577
1577
1656 }
executed: }
Execution Count:1699
1699
1657 }
executed: }
Execution Count:1699
1699
1658 -
1659#if defined(QABSTRACTSOCKET_DEBUG) -
1660 qDebug("QAbstractSocket::connectToHost(\"%s\", %i) == %s%s", hostName.toLatin1().constData(), port, -
1661 (d->state == ConnectedState) ? "true" : "false", -
1662 (d->state == ConnectingState || d->state == HostLookupState) -
1663 ? " (connection in progress)" : ""); -
1664#endif -
1665} -
1666 -
1667/*! \overload -
1668 -
1669 Attempts to make a connection to \a address on port \a port. -
1670*/ -
1671void QAbstractSocket::connectToHost(const QHostAddress &address, quint16 port, -
1672 OpenMode openMode) -
1673{ -
1674#if defined(QABSTRACTSOCKET_DEBUG) -
1675 qDebug("QAbstractSocket::connectToHost([%s], %i, %i)...", -
1676 address.toString().toLatin1().constData(), port, (int) openMode); -
1677#endif -
1678 connectToHost(address.toString(), port, openMode);
executed (the execution status of this line is deduced): connectToHost(address.toString(), port, openMode);
-
1679}
executed: }
Execution Count:54
54
1680 -
1681/*! -
1682 Returns the number of bytes that are waiting to be written. The -
1683 bytes are written when control goes back to the event loop or -
1684 when flush() is called. -
1685 -
1686 \sa bytesAvailable(), flush() -
1687*/ -
1688qint64 QAbstractSocket::bytesToWrite() const -
1689{ -
1690 Q_D(const QAbstractSocket);
executed (the execution status of this line is deduced): const QAbstractSocketPrivate * const d = d_func();
-
1691#if defined(QABSTRACTSOCKET_DEBUG) -
1692 qDebug("QAbstractSocket::bytesToWrite() == %i", d->writeBuffer.size()); -
1693#endif -
1694 return (qint64)d->writeBuffer.size();
executed: return (qint64)d->writeBuffer.size();
Execution Count:17851
17851
1695} -
1696 -
1697/*! -
1698 Returns the number of incoming bytes that are waiting to be read. -
1699 -
1700 \sa bytesToWrite(), read() -
1701*/ -
1702qint64 QAbstractSocket::bytesAvailable() const -
1703{ -
1704 Q_D(const QAbstractSocket);
executed (the execution status of this line is deduced): const QAbstractSocketPrivate * const d = d_func();
-
1705 qint64 available = QIODevice::bytesAvailable();
executed (the execution status of this line is deduced): qint64 available = QIODevice::bytesAvailable();
-
1706 -
1707 if (!d->isBuffered && d->socketEngine && d->socketEngine->isValid())
evaluated: !d->isBuffered
TRUEFALSE
yes
Evaluation Count:17559
yes
Evaluation Count:14948
evaluated: d->socketEngine
TRUEFALSE
yes
Evaluation Count:17512
yes
Evaluation Count:47
partially evaluated: d->socketEngine->isValid()
TRUEFALSE
yes
Evaluation Count:17512
no
Evaluation Count:0
0-17559
1708 available += d->socketEngine->bytesAvailable();
executed: available += d->socketEngine->bytesAvailable();
Execution Count:17512
17512
1709 -
1710#if defined(QABSTRACTSOCKET_DEBUG) -
1711 qDebug("QAbstractSocket::bytesAvailable() == %llu", available); -
1712#endif -
1713 return available;
executed: return available;
Execution Count:32507
32507
1714} -
1715 -
1716/*! -
1717 Returns the host port number (in native byte order) of the local -
1718 socket if available; otherwise returns 0. -
1719 -
1720 \sa localAddress(), peerPort(), setLocalPort() -
1721*/ -
1722quint16 QAbstractSocket::localPort() const -
1723{ -
1724 Q_D(const QAbstractSocket);
executed (the execution status of this line is deduced): const QAbstractSocketPrivate * const d = d_func();
-
1725 return d->localPort;
executed: return d->localPort;
Execution Count:423
423
1726} -
1727 -
1728/*! -
1729 Returns the host address of the local socket if available; -
1730 otherwise returns QHostAddress::Null. -
1731 -
1732 This is normally the main IP address of the host, but can be -
1733 QHostAddress::LocalHost (127.0.0.1) for connections to the -
1734 local host. -
1735 -
1736 \sa localPort(), peerAddress(), setLocalAddress() -
1737*/ -
1738QHostAddress QAbstractSocket::localAddress() const -
1739{ -
1740 Q_D(const QAbstractSocket);
executed (the execution status of this line is deduced): const QAbstractSocketPrivate * const d = d_func();
-
1741 return d->localAddress;
executed: return d->localAddress;
Execution Count:716
716
1742} -
1743 -
1744/*! -
1745 Returns the port of the connected peer if the socket is in -
1746 ConnectedState; otherwise returns 0. -
1747 -
1748 \sa peerAddress(), localPort(), setPeerPort() -
1749*/ -
1750quint16 QAbstractSocket::peerPort() const -
1751{ -
1752 Q_D(const QAbstractSocket);
executed (the execution status of this line is deduced): const QAbstractSocketPrivate * const d = d_func();
-
1753 return d->peerPort;
executed: return d->peerPort;
Execution Count:133
133
1754} -
1755 -
1756/*! -
1757 Returns the address of the connected peer if the socket is in -
1758 ConnectedState; otherwise returns QHostAddress::Null. -
1759 -
1760 \sa peerName(), peerPort(), localAddress(), setPeerAddress() -
1761*/ -
1762QHostAddress QAbstractSocket::peerAddress() const -
1763{ -
1764 Q_D(const QAbstractSocket);
executed (the execution status of this line is deduced): const QAbstractSocketPrivate * const d = d_func();
-
1765 return d->peerAddress;
executed: return d->peerAddress;
Execution Count:127
127
1766} -
1767 -
1768/*! -
1769 Returns the name of the peer as specified by connectToHost(), or -
1770 an empty QString if connectToHost() has not been called. -
1771 -
1772 \sa peerAddress(), peerPort(), setPeerName() -
1773*/ -
1774QString QAbstractSocket::peerName() const -
1775{ -
1776 Q_D(const QAbstractSocket);
executed (the execution status of this line is deduced): const QAbstractSocketPrivate * const d = d_func();
-
1777 return d->peerName.isEmpty() ? d->hostName : d->peerName;
executed: return d->peerName.isEmpty() ? d->hostName : d->peerName;
Execution Count:327
327
1778} -
1779 -
1780/*! -
1781 Returns true if a line of data can be read from the socket; -
1782 otherwise returns false. -
1783 -
1784 \sa readLine() -
1785*/ -
1786bool QAbstractSocket::canReadLine() const -
1787{ -
1788 bool hasLine = d_func()->buffer.canReadLine();
executed (the execution status of this line is deduced): bool hasLine = d_func()->buffer.canReadLine();
-
1789#if defined (QABSTRACTSOCKET_DEBUG) -
1790 qDebug("QAbstractSocket::canReadLine() == %s, buffer size = %d, size = %d", hasLine ? "true" : "false", -
1791 d_func()->buffer.size(), d_func()->buffer.size()); -
1792#endif -
1793 return hasLine || QIODevice::canReadLine();
executed: return hasLine || QIODevice::canReadLine();
Execution Count:1081
1081
1794} -
1795 -
1796/*! -
1797 Returns the native socket descriptor of the QAbstractSocket object -
1798 if this is available; otherwise returns -1. -
1799 -
1800 If the socket is using QNetworkProxy, the returned descriptor -
1801 may not be usable with native socket functions. -
1802 -
1803 The socket descriptor is not available when QAbstractSocket is in -
1804 UnconnectedState. -
1805 -
1806 \sa setSocketDescriptor() -
1807*/ -
1808qintptr QAbstractSocket::socketDescriptor() const -
1809{ -
1810 Q_D(const QAbstractSocket);
executed (the execution status of this line is deduced): const QAbstractSocketPrivate * const d = d_func();
-
1811 return d->cachedSocketDescriptor;
executed: return d->cachedSocketDescriptor;
Execution Count:290
290
1812} -
1813 -
1814/*! -
1815 Initializes QAbstractSocket with the native socket descriptor \a -
1816 socketDescriptor. Returns true if \a socketDescriptor is accepted -
1817 as a valid socket descriptor; otherwise returns false. -
1818 The socket is opened in the mode specified by \a openMode, and -
1819 enters the socket state specified by \a socketState. -
1820 -
1821 \b{Note:} It is not possible to initialize two abstract sockets -
1822 with the same native socket descriptor. -
1823 -
1824 \sa socketDescriptor() -
1825*/ -
1826bool QAbstractSocket::setSocketDescriptor(qintptr socketDescriptor, SocketState socketState, -
1827 OpenMode openMode) -
1828{ -
1829 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
1830 -
1831 d->resetSocketLayer();
executed (the execution status of this line is deduced): d->resetSocketLayer();
-
1832 d->socketEngine = QAbstractSocketEngine::createSocketEngine(socketDescriptor, this);
executed (the execution status of this line is deduced): d->socketEngine = QAbstractSocketEngine::createSocketEngine(socketDescriptor, this);
-
1833 if (!d->socketEngine) {
partially evaluated: !d->socketEngine
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:612
0-612
1834 d->socketError = UnsupportedSocketOperationError;
never executed (the execution status of this line is deduced): d->socketError = UnsupportedSocketOperationError;
-
1835 setErrorString(tr("Operation on socket is not supported"));
never executed (the execution status of this line is deduced): setErrorString(tr("Operation on socket is not supported"));
-
1836 return false;
never executed: return false;
0
1837 } -
1838#ifndef QT_NO_BEARERMANAGEMENT -
1839 //copy network session down to the socket engine (if it has been set) -
1840 d->socketEngine->setProperty("_q_networksession", property("_q_networksession"));
executed (the execution status of this line is deduced): d->socketEngine->setProperty("_q_networksession", property("_q_networksession"));
-
1841#endif -
1842 bool result = d->socketEngine->initialize(socketDescriptor, socketState);
executed (the execution status of this line is deduced): bool result = d->socketEngine->initialize(socketDescriptor, socketState);
-
1843 if (!result) {
evaluated: !result
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:611
1-611
1844 d->socketError = d->socketEngine->error();
executed (the execution status of this line is deduced): d->socketError = d->socketEngine->error();
-
1845 setErrorString(d->socketEngine->errorString());
executed (the execution status of this line is deduced): setErrorString(d->socketEngine->errorString());
-
1846 return false;
executed: return false;
Execution Count:1
1
1847 } -
1848 -
1849 if (d->threadData->eventDispatcher)
partially evaluated: d->threadData->eventDispatcher
TRUEFALSE
yes
Evaluation Count:611
no
Evaluation Count:0
0-611
1850 d->socketEngine->setReceiver(d);
executed: d->socketEngine->setReceiver(d);
Execution Count:611
611
1851 -
1852 QIODevice::open(openMode);
executed (the execution status of this line is deduced): QIODevice::open(openMode);
-
1853 -
1854 if (d->state != socketState) {
partially evaluated: d->state != socketState
TRUEFALSE
yes
Evaluation Count:611
no
Evaluation Count:0
0-611
1855 d->state = socketState;
executed (the execution status of this line is deduced): d->state = socketState;
-
1856 emit stateChanged(d->state);
executed (the execution status of this line is deduced): stateChanged(d->state);
-
1857 }
executed: }
Execution Count:611
611
1858 -
1859 d->pendingClose = false;
executed (the execution status of this line is deduced): d->pendingClose = false;
-
1860 d->socketEngine->setReadNotificationEnabled(true);
executed (the execution status of this line is deduced): d->socketEngine->setReadNotificationEnabled(true);
-
1861 d->localPort = d->socketEngine->localPort();
executed (the execution status of this line is deduced): d->localPort = d->socketEngine->localPort();
-
1862 d->peerPort = d->socketEngine->peerPort();
executed (the execution status of this line is deduced): d->peerPort = d->socketEngine->peerPort();
-
1863 d->localAddress = d->socketEngine->localAddress();
executed (the execution status of this line is deduced): d->localAddress = d->socketEngine->localAddress();
-
1864 d->peerAddress = d->socketEngine->peerAddress();
executed (the execution status of this line is deduced): d->peerAddress = d->socketEngine->peerAddress();
-
1865 d->cachedSocketDescriptor = socketDescriptor;
executed (the execution status of this line is deduced): d->cachedSocketDescriptor = socketDescriptor;
-
1866 -
1867 return true;
executed: return true;
Execution Count:611
611
1868} -
1869 -
1870/*! -
1871 \since 4.6 -
1872 Sets the given \a option to the value described by \a value. -
1873 -
1874 \sa socketOption() -
1875*/ -
1876void QAbstractSocket::setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value) -
1877{ -
1878 if (!d_func()->socketEngine)
partially evaluated: !d_func()->socketEngine
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:790
0-790
1879 return;
never executed: return;
0
1880 -
1881 switch (option) { -
1882 case LowDelayOption: -
1883 d_func()->socketEngine->setOption(QAbstractSocketEngine::LowDelayOption, value.toInt());
executed (the execution status of this line is deduced): d_func()->socketEngine->setOption(QAbstractSocketEngine::LowDelayOption, value.toInt());
-
1884 break;
executed: break;
Execution Count:36
36
1885 -
1886 case KeepAliveOption: -
1887 d_func()->socketEngine->setOption(QAbstractSocketEngine::KeepAliveOption, value.toInt());
executed (the execution status of this line is deduced): d_func()->socketEngine->setOption(QAbstractSocketEngine::KeepAliveOption, value.toInt());
-
1888 break;
executed: break;
Execution Count:702
702
1889 -
1890 case MulticastTtlOption: -
1891 d_func()->socketEngine->setOption(QAbstractSocketEngine::MulticastTtlOption, value.toInt());
executed (the execution status of this line is deduced): d_func()->socketEngine->setOption(QAbstractSocketEngine::MulticastTtlOption, value.toInt());
-
1892 break;
executed: break;
Execution Count:24
24
1893 -
1894 case MulticastLoopbackOption: -
1895 d_func()->socketEngine->setOption(QAbstractSocketEngine::MulticastLoopbackOption, value.toInt());
executed (the execution status of this line is deduced): d_func()->socketEngine->setOption(QAbstractSocketEngine::MulticastLoopbackOption, value.toInt());
-
1896 break;
executed: break;
Execution Count:28
28
1897 -
1898 case TypeOfServiceOption: -
1899 d_func()->socketEngine->setOption(QAbstractSocketEngine::TypeOfServiceOption, value.toInt());
never executed (the execution status of this line is deduced): d_func()->socketEngine->setOption(QAbstractSocketEngine::TypeOfServiceOption, value.toInt());
-
1900 break;
never executed: break;
0
1901 } -
1902}
executed: }
Execution Count:790
790
1903 -
1904/*! -
1905 \since 4.6 -
1906 Returns the value of the \a option option. -
1907 -
1908 \sa setSocketOption() -
1909*/ -
1910QVariant QAbstractSocket::socketOption(QAbstractSocket::SocketOption option) -
1911{ -
1912 if (!d_func()->socketEngine)
partially evaluated: !d_func()->socketEngine
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:52
0-52
1913 return QVariant();
never executed: return QVariant();
0
1914 -
1915 int ret = -1;
executed (the execution status of this line is deduced): int ret = -1;
-
1916 switch (option) { -
1917 case LowDelayOption: -
1918 ret = d_func()->socketEngine->option(QAbstractSocketEngine::LowDelayOption);
never executed (the execution status of this line is deduced): ret = d_func()->socketEngine->option(QAbstractSocketEngine::LowDelayOption);
-
1919 break;
never executed: break;
0
1920 -
1921 case KeepAliveOption: -
1922 ret = d_func()->socketEngine->option(QAbstractSocketEngine::KeepAliveOption);
never executed (the execution status of this line is deduced): ret = d_func()->socketEngine->option(QAbstractSocketEngine::KeepAliveOption);
-
1923 break;
never executed: break;
0
1924 -
1925 case MulticastTtlOption: -
1926 ret = d_func()->socketEngine->option(QAbstractSocketEngine::MulticastTtlOption);
executed (the execution status of this line is deduced): ret = d_func()->socketEngine->option(QAbstractSocketEngine::MulticastTtlOption);
-
1927 break;
executed: break;
Execution Count:24
24
1928 case MulticastLoopbackOption: -
1929 ret = d_func()->socketEngine->option(QAbstractSocketEngine::MulticastLoopbackOption);
executed (the execution status of this line is deduced): ret = d_func()->socketEngine->option(QAbstractSocketEngine::MulticastLoopbackOption);
-
1930 break;
executed: break;
Execution Count:28
28
1931 -
1932 case TypeOfServiceOption: -
1933 ret = d_func()->socketEngine->option(QAbstractSocketEngine::TypeOfServiceOption);
never executed (the execution status of this line is deduced): ret = d_func()->socketEngine->option(QAbstractSocketEngine::TypeOfServiceOption);
-
1934 break;
never executed: break;
0
1935 } -
1936 if (ret == -1)
evaluated: ret == -1
TRUEFALSE
yes
Evaluation Count:26
yes
Evaluation Count:26
26
1937 return QVariant();
executed: return QVariant();
Execution Count:26
26
1938 else -
1939 return QVariant(ret);
executed: return QVariant(ret);
Execution Count:26
26
1940} -
1941 -
1942 -
1943/* -
1944 Returns the difference between msecs and elapsed. If msecs is -1, -
1945 however, -1 is returned. -
1946*/ -
1947static int qt_timeout_value(int msecs, int elapsed) -
1948{ -
1949 if (msecs == -1)
evaluated: msecs == -1
TRUEFALSE
yes
Evaluation Count:11192
yes
Evaluation Count:7688
7688-11192
1950 return -1;
executed: return -1;
Execution Count:11192
11192
1951 -
1952 int timeout = msecs - elapsed;
executed (the execution status of this line is deduced): int timeout = msecs - elapsed;
-
1953 return timeout < 0 ? 0 : timeout;
executed: return timeout < 0 ? 0 : timeout;
Execution Count:7688
7688
1954} -
1955 -
1956/*! -
1957 Waits until the socket is connected, up to \a msecs -
1958 milliseconds. If the connection has been established, this -
1959 function returns true; otherwise it returns false. In the case -
1960 where it returns false, you can call error() to determine -
1961 the cause of the error. -
1962 -
1963 The following example waits up to one second for a connection -
1964 to be established: -
1965 -
1966 \snippet code/src_network_socket_qabstractsocket.cpp 0 -
1967 -
1968 If msecs is -1, this function will not time out. -
1969 -
1970 \note This function may wait slightly longer than \a msecs, -
1971 depending on the time it takes to complete the host lookup. -
1972 -
1973 \note Multiple calls to this functions do not accumulate the time. -
1974 If the function times out, the connecting process will be aborted. -
1975 -
1976 \sa connectToHost(), connected() -
1977*/ -
1978bool QAbstractSocket::waitForConnected(int msecs) -
1979{ -
1980 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
1981#if defined (QABSTRACTSOCKET_DEBUG) -
1982 qDebug("QAbstractSocket::waitForConnected(%i)", msecs); -
1983#endif -
1984 -
1985 if (state() == ConnectedState) {
evaluated: state() == ConnectedState
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:422
6-422
1986#if defined (QABSTRACTSOCKET_DEBUG) -
1987 qDebug("QAbstractSocket::waitForConnected(%i) already connected", msecs); -
1988#endif -
1989 return true;
executed: return true;
Execution Count:6
6
1990 } -
1991 -
1992 bool wasPendingClose = d->pendingClose;
executed (the execution status of this line is deduced): bool wasPendingClose = d->pendingClose;
-
1993 d->pendingClose = false;
executed (the execution status of this line is deduced): d->pendingClose = false;
-
1994 QElapsedTimer stopWatch;
executed (the execution status of this line is deduced): QElapsedTimer stopWatch;
-
1995 stopWatch.start();
executed (the execution status of this line is deduced): stopWatch.start();
-
1996 -
1997 if (d->state == HostLookupState) {
evaluated: d->state == HostLookupState
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:420
2-420
1998#if defined (QABSTRACTSOCKET_DEBUG) -
1999 qDebug("QAbstractSocket::waitForConnected(%i) doing host name lookup", msecs); -
2000#endif -
2001 QHostInfo::abortHostLookup(d->hostLookupId);
executed (the execution status of this line is deduced): QHostInfo::abortHostLookup(d->hostLookupId);
-
2002 d->hostLookupId = -1;
executed (the execution status of this line is deduced): d->hostLookupId = -1;
-
2003#ifndef QT_NO_BEARERMANAGEMENT -
2004 QSharedPointer<QNetworkSession> networkSession;
executed (the execution status of this line is deduced): QSharedPointer<QNetworkSession> networkSession;
-
2005 QVariant v(property("_q_networksession"));
executed (the execution status of this line is deduced): QVariant v(property("_q_networksession"));
-
2006 if (v.isValid()) {
partially evaluated: v.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
2007 networkSession = qvariant_cast< QSharedPointer<QNetworkSession> >(v);
never executed (the execution status of this line is deduced): networkSession = qvariant_cast< QSharedPointer<QNetworkSession> >(v);
-
2008 d->_q_startConnecting(QHostInfoPrivate::fromName(d->hostName, networkSession));
never executed (the execution status of this line is deduced): d->_q_startConnecting(QHostInfoPrivate::fromName(d->hostName, networkSession));
-
2009 } else
never executed: }
0
2010#endif -
2011 { -
2012 QHostAddress temp;
executed (the execution status of this line is deduced): QHostAddress temp;
-
2013 if (temp.setAddress(d->hostName)) {
partially evaluated: temp.setAddress(d->hostName)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
2014 QHostInfo info;
never executed (the execution status of this line is deduced): QHostInfo info;
-
2015 info.setAddresses(QList<QHostAddress>() << temp);
never executed (the execution status of this line is deduced): info.setAddresses(QList<QHostAddress>() << temp);
-
2016 d->_q_startConnecting(info);
never executed (the execution status of this line is deduced): d->_q_startConnecting(info);
-
2017 } else {
never executed: }
0
2018 d->_q_startConnecting(QHostInfo::fromName(d->hostName));
executed (the execution status of this line is deduced): d->_q_startConnecting(QHostInfo::fromName(d->hostName));
-
2019 }
executed: }
Execution Count:2
2
2020 } -
2021 } -
2022 if (state() == UnconnectedState)
evaluated: state() == UnconnectedState
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:419
3-419
2023 return false; // connect not im progress anymore!
executed: return false;
Execution Count:3
3
2024 -
2025 bool timedOut = true;
executed (the execution status of this line is deduced): bool timedOut = true;
-
2026#if defined (QABSTRACTSOCKET_DEBUG) -
2027 int attempt = 1; -
2028#endif -
2029 while (state() == ConnectingState && (msecs == -1 || stopWatch.elapsed() < msecs)) {
evaluated: state() == ConnectingState
TRUEFALSE
yes
Evaluation Count:422
yes
Evaluation Count:419
partially evaluated: msecs == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:422
partially evaluated: stopWatch.elapsed() < msecs
TRUEFALSE
yes
Evaluation Count:422
no
Evaluation Count:0
0-422
2030 int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
executed (the execution status of this line is deduced): int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
-
2031 if (msecs != -1 && timeout > QT_CONNECT_TIMEOUT)
partially evaluated: msecs != -1
TRUEFALSE
yes
Evaluation Count:422
no
Evaluation Count:0
partially evaluated: timeout > 30000
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:422
0-422
2032 timeout = QT_CONNECT_TIMEOUT;
never executed: timeout = 30000;
0
2033#if defined (QABSTRACTSOCKET_DEBUG) -
2034 qDebug("QAbstractSocket::waitForConnected(%i) waiting %.2f secs for connection attempt #%i", -
2035 msecs, timeout / 1000.0, attempt++); -
2036#endif -
2037 timedOut = false;
executed (the execution status of this line is deduced): timedOut = false;
-
2038 -
2039 if (d->socketEngine && d->socketEngine->waitForWrite(timeout, &timedOut) && !timedOut) {
partially evaluated: d->socketEngine
TRUEFALSE
yes
Evaluation Count:422
no
Evaluation Count:0
partially evaluated: d->socketEngine->waitForWrite(timeout, &timedOut)
TRUEFALSE
yes
Evaluation Count:422
no
Evaluation Count:0
partially evaluated: !timedOut
TRUEFALSE
yes
Evaluation Count:422
no
Evaluation Count:0
0-422
2040 d->_q_testConnection();
executed (the execution status of this line is deduced): d->_q_testConnection();
-
2041 } else {
executed: }
Execution Count:422
422
2042 d->_q_connectToNextAddress();
never executed (the execution status of this line is deduced): d->_q_connectToNextAddress();
-
2043 }
never executed: }
0
2044 } -
2045 -
2046 if ((timedOut && state() != ConnectedState) || state() == ConnectingState) {
partially evaluated: timedOut
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:419
never evaluated: state() != ConnectedState
partially evaluated: state() == ConnectingState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:419
0-419
2047 d->socketError = SocketTimeoutError;
never executed (the execution status of this line is deduced): d->socketError = SocketTimeoutError;
-
2048 d->state = UnconnectedState;
never executed (the execution status of this line is deduced): d->state = UnconnectedState;
-
2049 emit stateChanged(d->state);
never executed (the execution status of this line is deduced): stateChanged(d->state);
-
2050 d->resetSocketLayer();
never executed (the execution status of this line is deduced): d->resetSocketLayer();
-
2051 setErrorString(tr("Socket operation timed out"));
never executed (the execution status of this line is deduced): setErrorString(tr("Socket operation timed out"));
-
2052 }
never executed: }
0
2053 -
2054#if defined (QABSTRACTSOCKET_DEBUG) -
2055 qDebug("QAbstractSocket::waitForConnected(%i) == %s", msecs, -
2056 state() == ConnectedState ? "true" : "false"); -
2057#endif -
2058 if (state() != ConnectedState)
evaluated: state() != ConnectedState
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:416
3-416
2059 return false;
executed: return false;
Execution Count:3
3
2060 if (wasPendingClose)
partially evaluated: wasPendingClose
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:416
0-416
2061 disconnectFromHost();
never executed: disconnectFromHost();
0
2062 return true;
executed: return true;
Execution Count:416
416
2063} -
2064 -
2065/*! -
2066 This function blocks until new data is available for reading and the -
2067 \l{QIODevice::}{readyRead()} signal has been emitted. The function -
2068 will timeout after \a msecs milliseconds; the default timeout is -
2069 30000 milliseconds. -
2070 -
2071 The function returns true if the readyRead() signal is emitted and -
2072 there is new data available for reading; otherwise it returns false -
2073 (if an error occurred or the operation timed out). -
2074 -
2075 \sa waitForBytesWritten() -
2076*/ -
2077bool QAbstractSocket::waitForReadyRead(int msecs) -
2078{ -
2079 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
2080#if defined (QABSTRACTSOCKET_DEBUG) -
2081 qDebug("QAbstractSocket::waitForReadyRead(%i)", msecs); -
2082#endif -
2083 -
2084 // require calling connectToHost() before waitForReadyRead() -
2085 if (state() == UnconnectedState) {
evaluated: state() == UnconnectedState
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:11873
24-11873
2086 /* If all you have is a QIODevice pointer to an abstractsocket, you cannot check -
2087 this, so you cannot avoid this warning. */ -
2088// qWarning("QAbstractSocket::waitForReadyRead() is not allowed in UnconnectedState"); -
2089 return false;
executed: return false;
Execution Count:24
24
2090 } -
2091 -
2092 QElapsedTimer stopWatch;
executed (the execution status of this line is deduced): QElapsedTimer stopWatch;
-
2093 stopWatch.start();
executed (the execution status of this line is deduced): stopWatch.start();
-
2094 -
2095 // handle a socket in connecting state -
2096 if (state() == HostLookupState || state() == ConnectingState) {
evaluated: state() == HostLookupState
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:11872
evaluated: state() == ConnectingState
TRUEFALSE
yes
Evaluation Count:81
yes
Evaluation Count:11791
1-11872
2097 if (!waitForConnected(msecs))
evaluated: !waitForConnected(msecs)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:81
1-81
2098 return false;
executed: return false;
Execution Count:1
1
2099 }
executed: }
Execution Count:81
81
2100 -
2101 Q_ASSERT(d->socketEngine);
executed (the execution status of this line is deduced): qt_noop();
-
2102 do { -
2103 bool readyToRead = false;
executed (the execution status of this line is deduced): bool readyToRead = false;
-
2104 bool readyToWrite = false;
executed (the execution status of this line is deduced): bool readyToWrite = false;
-
2105 if (!d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite, true, !d->writeBuffer.isEmpty(),
evaluated: !d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite, true, !d->writeBuffer.isEmpty(), qt_timeout_value(msecs, stopWatch.elapsed()))
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:11947
11-11947
2106 qt_timeout_value(msecs, stopWatch.elapsed()))) {
evaluated: !d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite, true, !d->writeBuffer.isEmpty(), qt_timeout_value(msecs, stopWatch.elapsed()))
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:11947
11-11947
2107 d->socketError = d->socketEngine->error();
executed (the execution status of this line is deduced): d->socketError = d->socketEngine->error();
-
2108 setErrorString(d->socketEngine->errorString());
executed (the execution status of this line is deduced): setErrorString(d->socketEngine->errorString());
-
2109#if defined (QABSTRACTSOCKET_DEBUG) -
2110 qDebug("QAbstractSocket::waitForReadyRead(%i) failed (%i, %s)", -
2111 msecs, d->socketError, errorString().toLatin1().constData()); -
2112#endif -
2113 emit error(d->socketError);
executed (the execution status of this line is deduced): error(d->socketError);
-
2114 if (d->socketError != SocketTimeoutError)
partially evaluated: d->socketError != SocketTimeoutError
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:11
0-11
2115 close();
never executed: close();
0
2116 return false;
executed: return false;
Execution Count:11
11
2117 } -
2118 -
2119 if (readyToRead) {
evaluated: readyToRead
TRUEFALSE
yes
Evaluation Count:11861
yes
Evaluation Count:86
86-11861
2120 if (d->canReadNotification())
evaluated: d->canReadNotification()
TRUEFALSE
yes
Evaluation Count:11855
yes
Evaluation Count:6
6-11855
2121 return true;
executed: return true;
Execution Count:11855
11855
2122 }
executed: }
Execution Count:6
6
2123 -
2124 if (readyToWrite)
evaluated: readyToWrite
TRUEFALSE
yes
Evaluation Count:86
yes
Evaluation Count:6
6-86
2125 d->canWriteNotification();
executed: d->canWriteNotification();
Execution Count:86
86
2126 -
2127 if (state() != ConnectedState)
evaluated: state() != ConnectedState
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:86
6-86
2128 return false;
executed: return false;
Execution Count:6
6
2129 } while (msecs == -1 || qt_timeout_value(msecs, stopWatch.elapsed()) > 0);
executed: }
Execution Count:86
partially evaluated: msecs == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:86
partially evaluated: qt_timeout_value(msecs, stopWatch.elapsed()) > 0
TRUEFALSE
yes
Evaluation Count:86
no
Evaluation Count:0
0-86
2130 return false;
never executed: return false;
0
2131} -
2132 -
2133/*! \reimp -
2134 */ -
2135bool QAbstractSocket::waitForBytesWritten(int msecs) -
2136{ -
2137 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
2138#if defined (QABSTRACTSOCKET_DEBUG) -
2139 qDebug("QAbstractSocket::waitForBytesWritten(%i)", msecs); -
2140#endif -
2141 -
2142 // require calling connectToHost() before waitForBytesWritten() -
2143 if (state() == UnconnectedState) {
partially evaluated: state() == UnconnectedState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5126
0-5126
2144 qWarning("QAbstractSocket::waitForBytesWritten() is not allowed in UnconnectedState");
never executed (the execution status of this line is deduced): QMessageLogger("socket/qabstractsocket.cpp", 2144, __PRETTY_FUNCTION__).warning("QAbstractSocket::waitForBytesWritten() is not allowed in UnconnectedState");
-
2145 return false;
never executed: return false;
0
2146 } -
2147 -
2148 if (d->writeBuffer.isEmpty())
evaluated: d->writeBuffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:99
yes
Evaluation Count:5027
99-5027
2149 return false;
executed: return false;
Execution Count:99
99
2150 -
2151 QElapsedTimer stopWatch;
executed (the execution status of this line is deduced): QElapsedTimer stopWatch;
-
2152 stopWatch.start();
executed (the execution status of this line is deduced): stopWatch.start();
-
2153 -
2154 // handle a socket in connecting state -
2155 if (state() == HostLookupState || state() == ConnectingState) {
partially evaluated: state() == HostLookupState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5027
partially evaluated: state() == ConnectingState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5027
0-5027
2156 if (!waitForConnected(msecs))
never evaluated: !waitForConnected(msecs)
0
2157 return false;
never executed: return false;
0
2158 }
never executed: }
0
2159 -
2160 forever {
executed (the execution status of this line is deduced): for(;;) {
-
2161 bool readyToRead = false;
executed (the execution status of this line is deduced): bool readyToRead = false;
-
2162 bool readyToWrite = false;
executed (the execution status of this line is deduced): bool readyToWrite = false;
-
2163 if (!d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite, true, !d->writeBuffer.isEmpty(),
evaluated: !d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite, true, !d->writeBuffer.isEmpty(), qt_timeout_value(msecs, stopWatch.elapsed()))
TRUEFALSE
yes
Evaluation Count:21
yes
Evaluation Count:5006
21-5006
2164 qt_timeout_value(msecs, stopWatch.elapsed()))) {
evaluated: !d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite, true, !d->writeBuffer.isEmpty(), qt_timeout_value(msecs, stopWatch.elapsed()))
TRUEFALSE
yes
Evaluation Count:21
yes
Evaluation Count:5006
21-5006
2165 d->socketError = d->socketEngine->error();
executed (the execution status of this line is deduced): d->socketError = d->socketEngine->error();
-
2166 setErrorString(d->socketEngine->errorString());
executed (the execution status of this line is deduced): setErrorString(d->socketEngine->errorString());
-
2167#if defined (QABSTRACTSOCKET_DEBUG) -
2168 qDebug("QAbstractSocket::waitForBytesWritten(%i) failed (%i, %s)", -
2169 msecs, d->socketError, errorString().toLatin1().constData()); -
2170#endif -
2171 emit error(d->socketError);
executed (the execution status of this line is deduced): error(d->socketError);
-
2172 if (d->socketError != SocketTimeoutError)
partially evaluated: d->socketError != SocketTimeoutError
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21
0-21
2173 close();
never executed: close();
0
2174 return false;
executed: return false;
Execution Count:21
21
2175 } -
2176 -
2177 if (readyToRead) {
partially evaluated: readyToRead
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5006
0-5006
2178#if defined (QABSTRACTSOCKET_DEBUG) -
2179 qDebug("QAbstractSocket::waitForBytesWritten calls canReadNotification"); -
2180#endif -
2181 if(!d->canReadNotification())
never evaluated: !d->canReadNotification()
0
2182 return false;
never executed: return false;
0
2183 }
never executed: }
0
2184 -
2185 -
2186 if (readyToWrite) {
partially evaluated: readyToWrite
TRUEFALSE
yes
Evaluation Count:5006
no
Evaluation Count:0
0-5006
2187 if (d->canWriteNotification()) {
partially evaluated: d->canWriteNotification()
TRUEFALSE
yes
Evaluation Count:5006
no
Evaluation Count:0
0-5006
2188#if defined (QABSTRACTSOCKET_DEBUG) -
2189 qDebug("QAbstractSocket::waitForBytesWritten returns true"); -
2190#endif -
2191 return true;
executed: return true;
Execution Count:5006
5006
2192 } -
2193 }
never executed: }
0
2194 -
2195 if (state() != ConnectedState)
never evaluated: state() != ConnectedState
0
2196 return false;
never executed: return false;
0
2197 }
never executed: }
0
2198 return false;
never executed: return false;
0
2199} -
2200 -
2201/*! -
2202 Waits until the socket has disconnected, up to \a msecs -
2203 milliseconds. If the connection has been disconnected, this -
2204 function returns true; otherwise it returns false. In the case -
2205 where it returns false, you can call error() to determine -
2206 the cause of the error. -
2207 -
2208 The following example waits up to one second for a connection -
2209 to be closed: -
2210 -
2211 \snippet code/src_network_socket_qabstractsocket.cpp 1 -
2212 -
2213 If msecs is -1, this function will not time out. -
2214 -
2215 \sa disconnectFromHost(), close() -
2216*/ -
2217bool QAbstractSocket::waitForDisconnected(int msecs) -
2218{ -
2219 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
2220 -
2221 // require calling connectToHost() before waitForDisconnected() -
2222 if (state() == UnconnectedState) {
partially evaluated: state() == UnconnectedState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:71
0-71
2223 qWarning("QAbstractSocket::waitForDisconnected() is not allowed in UnconnectedState");
never executed (the execution status of this line is deduced): QMessageLogger("socket/qabstractsocket.cpp", 2223, __PRETTY_FUNCTION__).warning("QAbstractSocket::waitForDisconnected() is not allowed in UnconnectedState");
-
2224 return false;
never executed: return false;
0
2225 } -
2226 -
2227 QElapsedTimer stopWatch;
executed (the execution status of this line is deduced): QElapsedTimer stopWatch;
-
2228 stopWatch.start();
executed (the execution status of this line is deduced): stopWatch.start();
-
2229 -
2230 // handle a socket in connecting state -
2231 if (state() == HostLookupState || state() == ConnectingState) {
partially evaluated: state() == HostLookupState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:71
evaluated: state() == ConnectingState
TRUEFALSE
yes
Evaluation Count:28
yes
Evaluation Count:43
0-71
2232 if (!waitForConnected(msecs))
partially evaluated: !waitForConnected(msecs)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:28
0-28
2233 return false;
never executed: return false;
0
2234 if (state() == UnconnectedState)
partially evaluated: state() == UnconnectedState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:28
0-28
2235 return true;
never executed: return true;
0
2236 }
executed: }
Execution Count:28
28
2237 -
2238 forever {
executed (the execution status of this line is deduced): for(;;) {
-
2239 bool readyToRead = false;
executed (the execution status of this line is deduced): bool readyToRead = false;
-
2240 bool readyToWrite = false;
executed (the execution status of this line is deduced): bool readyToWrite = false;
-
2241 if (!d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite, state() == ConnectedState,
partially evaluated: !d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite, state() == ConnectedState, !d->writeBuffer.isEmpty(), qt_timeout_value(msecs, stopWatch.elapsed()))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1388
0-1388
2242 !d->writeBuffer.isEmpty(),
partially evaluated: !d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite, state() == ConnectedState, !d->writeBuffer.isEmpty(), qt_timeout_value(msecs, stopWatch.elapsed()))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1388
0-1388
2243 qt_timeout_value(msecs, stopWatch.elapsed()))) {
partially evaluated: !d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite, state() == ConnectedState, !d->writeBuffer.isEmpty(), qt_timeout_value(msecs, stopWatch.elapsed()))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1388
0-1388
2244 d->socketError = d->socketEngine->error();
never executed (the execution status of this line is deduced): d->socketError = d->socketEngine->error();
-
2245 setErrorString(d->socketEngine->errorString());
never executed (the execution status of this line is deduced): setErrorString(d->socketEngine->errorString());
-
2246#if defined (QABSTRACTSOCKET_DEBUG) -
2247 qDebug("QAbstractSocket::waitForReadyRead(%i) failed (%i, %s)", -
2248 msecs, d->socketError, errorString().toLatin1().constData()); -
2249#endif -
2250 emit error(d->socketError);
never executed (the execution status of this line is deduced): error(d->socketError);
-
2251 if (d->socketError != SocketTimeoutError)
never evaluated: d->socketError != SocketTimeoutError
0
2252 close();
never executed: close();
0
2253 return false;
never executed: return false;
0
2254 } -
2255 -
2256 if (readyToRead)
evaluated: readyToRead
TRUEFALSE
yes
Evaluation Count:1360
yes
Evaluation Count:28
28-1360
2257 d->canReadNotification();
executed: d->canReadNotification();
Execution Count:1360
1360
2258 if (readyToWrite)
evaluated: readyToWrite
TRUEFALSE
yes
Evaluation Count:28
yes
Evaluation Count:1360
28-1360
2259 d->canWriteNotification();
executed: d->canWriteNotification();
Execution Count:28
28
2260 -
2261 if (state() == UnconnectedState)
evaluated: state() == UnconnectedState
TRUEFALSE
yes
Evaluation Count:71
yes
Evaluation Count:1317
71-1317
2262 return true;
executed: return true;
Execution Count:71
71
2263 }
executed: }
Execution Count:1317
1317
2264 return false;
never executed: return false;
0
2265} -
2266 -
2267/*! -
2268 Aborts the current connection and resets the socket. Unlike disconnectFromHost(), -
2269 this function immediately closes the socket, discarding any pending data in the -
2270 write buffer. -
2271 -
2272 \sa disconnectFromHost(), close() -
2273*/ -
2274void QAbstractSocket::abort() -
2275{ -
2276 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
2277#if defined (QABSTRACTSOCKET_DEBUG) -
2278 qDebug("QAbstractSocket::abort()"); -
2279#endif -
2280 if (d->state == UnconnectedState)
evaluated: d->state == UnconnectedState
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1659
1-1659
2281 return;
executed: return;
Execution Count:1
1
2282#ifndef QT_NO_SSL -
2283 if (QSslSocket *socket = qobject_cast<QSslSocket *>(this)) {
partially evaluated: QSslSocket *socket = qobject_cast<QSslSocket *>(this)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1659
0-1659
2284 socket->abort();
never executed (the execution status of this line is deduced): socket->abort();
-
2285 return;
never executed: return;
0
2286 } -
2287#endif -
2288 if (d->connectTimer) {
evaluated: d->connectTimer
TRUEFALSE
yes
Evaluation Count:1107
yes
Evaluation Count:552
552-1107
2289 d->connectTimer->stop();
executed (the execution status of this line is deduced): d->connectTimer->stop();
-
2290 delete d->connectTimer;
executed (the execution status of this line is deduced): delete d->connectTimer;
-
2291 d->connectTimer = 0;
executed (the execution status of this line is deduced): d->connectTimer = 0;
-
2292 }
executed: }
Execution Count:1107
1107
2293 -
2294 d->writeBuffer.clear();
executed (the execution status of this line is deduced): d->writeBuffer.clear();
-
2295 d->abortCalled = true;
executed (the execution status of this line is deduced): d->abortCalled = true;
-
2296 close();
executed (the execution status of this line is deduced): close();
-
2297}
executed: }
Execution Count:1659
1659
2298 -
2299/*! \reimp -
2300*/ -
2301bool QAbstractSocket::isSequential() const -
2302{ -
2303 return true;
executed: return true;
Execution Count:1985
1985
2304} -
2305 -
2306/*! \reimp -
2307 -
2308 Returns true if no more data is currently -
2309 available for reading; otherwise returns false. -
2310 -
2311 This function is most commonly used when reading data from the -
2312 socket in a loop. For example: -
2313 -
2314 \snippet code/src_network_socket_qabstractsocket.cpp 2 -
2315 -
2316 \sa bytesAvailable(), readyRead() -
2317 */ -
2318bool QAbstractSocket::atEnd() const -
2319{ -
2320 return QIODevice::atEnd() && (!isOpen() || d_func()->buffer.isEmpty());
executed: return QIODevice::atEnd() && (!isOpen() || d_func()->buffer.isEmpty());
Execution Count:278
278
2321} -
2322 -
2323/*! -
2324 This function writes as much as possible from the internal write buffer to -
2325 the underlying network socket, without blocking. If any data was written, -
2326 this function returns true; otherwise false is returned. -
2327 -
2328 Call this function if you need QAbstractSocket to start sending buffered -
2329 data immediately. The number of bytes successfully written depends on the -
2330 operating system. In most cases, you do not need to call this function, -
2331 because QAbstractSocket will start sending data automatically once control -
2332 goes back to the event loop. In the absence of an event loop, call -
2333 waitForBytesWritten() instead. -
2334 -
2335 \sa write(), waitForBytesWritten() -
2336*/ -
2337// Note! docs copied to QSslSocket::flush() -
2338bool QAbstractSocket::flush() -
2339{ -
2340 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
2341#ifndef QT_NO_SSL -
2342 // Manual polymorphism; flush() isn't virtual, but QSslSocket overloads -
2343 // it. -
2344 if (QSslSocket *socket = qobject_cast<QSslSocket *>(this))
partially evaluated: QSslSocket *socket = qobject_cast<QSslSocket *>(this)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12189
0-12189
2345 return socket->flush();
never executed: return socket->flush();
0
2346#endif -
2347 Q_CHECK_SOCKETENGINE(false);
executed: return false;
Execution Count:7
executed: }
Execution Count:12182
evaluated: !d->socketEngine
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:12182
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12182
0-12182
2348 return d->flush();
executed: return d->flush();
Execution Count:12182
12182
2349} -
2350 -
2351/*! \reimp -
2352*/ -
2353qint64 QAbstractSocket::readData(char *data, qint64 maxSize) -
2354{ -
2355 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
2356 -
2357 // Check if the read notifier can be enabled again. -
2358 if (d->socketEngine && !d->socketEngine->isReadNotificationEnabled() && d->socketEngine->isValid())
evaluated: d->socketEngine
TRUEFALSE
yes
Evaluation Count:308803
yes
Evaluation Count:5627
evaluated: !d->socketEngine->isReadNotificationEnabled()
TRUEFALSE
yes
Evaluation Count:6055
yes
Evaluation Count:302748
partially evaluated: d->socketEngine->isValid()
TRUEFALSE
yes
Evaluation Count:6055
no
Evaluation Count:0
0-308803
2359 d->socketEngine->setReadNotificationEnabled(true);
executed: d->socketEngine->setReadNotificationEnabled(true);
Execution Count:6055
6055
2360 -
2361 if (!maxSize)
evaluated: !maxSize
TRUEFALSE
yes
Evaluation Count:154003
yes
Evaluation Count:160427
154003-160427
2362 return 0;
executed: return 0;
Execution Count:154003
154003
2363 -
2364 // This is for a buffered QTcpSocket -
2365 if (d->isBuffered && d->buffer.isEmpty())
evaluated: d->isBuffered
TRUEFALSE
yes
Evaluation Count:24769
yes
Evaluation Count:135658
evaluated: d->buffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:18954
yes
Evaluation Count:5815
5815-135658
2366 // if we're still connected, return 0 indicating there may be more data in the future -
2367 // if we're not connected, return -1 indicating EOF -
2368 return d->state == QAbstractSocket::ConnectedState ? qint64(0) : qint64(-1);
executed: return d->state == QAbstractSocket::ConnectedState ? qint64(0) : qint64(-1);
Execution Count:18954
18954
2369 -
2370 if (!d->socketEngine)
evaluated: !d->socketEngine
TRUEFALSE
yes
Evaluation Count:2719
yes
Evaluation Count:138754
2719-138754
2371 return -1; // no socket engine is probably EOF
executed: return -1;
Execution Count:2719
2719
2372 if (!d->socketEngine->isValid())
partially evaluated: !d->socketEngine->isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:138754
0-138754
2373 return -1; // This is for unbuffered TCP when we already had been disconnected
never executed: return -1;
0
2374 if (d->state != QAbstractSocket::ConnectedState)
partially evaluated: d->state != QAbstractSocket::ConnectedState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:138754
0-138754
2375 return -1; // This is for unbuffered TCP if we're not connected yet
never executed: return -1;
0
2376 qint64 readBytes = d->socketEngine->read(data, maxSize);
executed (the execution status of this line is deduced): qint64 readBytes = d->socketEngine->read(data, maxSize);
-
2377 if (readBytes == -2) {
evaluated: readBytes == -2
TRUEFALSE
yes
Evaluation Count:5263
yes
Evaluation Count:133491
5263-133491
2378 // -2 from the engine means no bytes available (EAGAIN) so read more later -
2379 return 0;
executed: return 0;
Execution Count:5263
5263
2380 } else if (readBytes < 0) {
evaluated: readBytes < 0
TRUEFALSE
yes
Evaluation Count:128
yes
Evaluation Count:133363
128-133363
2381 d->socketError = d->socketEngine->error();
executed (the execution status of this line is deduced): d->socketError = d->socketEngine->error();
-
2382 setErrorString(d->socketEngine->errorString());
executed (the execution status of this line is deduced): setErrorString(d->socketEngine->errorString());
-
2383 d->resetSocketLayer();
executed (the execution status of this line is deduced): d->resetSocketLayer();
-
2384 d->state = QAbstractSocket::UnconnectedState;
executed (the execution status of this line is deduced): d->state = QAbstractSocket::UnconnectedState;
-
2385 } else if (!d->socketEngine->isReadNotificationEnabled()) {
executed: }
Execution Count:128
partially evaluated: !d->socketEngine->isReadNotificationEnabled()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:133363
0-133363
2386 // Only do this when there was no error -
2387 d->socketEngine->setReadNotificationEnabled(true);
never executed (the execution status of this line is deduced): d->socketEngine->setReadNotificationEnabled(true);
-
2388 }
never executed: }
0
2389 -
2390#if defined (QABSTRACTSOCKET_DEBUG) -
2391 qDebug("QAbstractSocket::readData(%p \"%s\", %lli) == %lld [engine]", -
2392 data, qt_prettyDebug(data, 32, readBytes).data(), maxSize, -
2393 readBytes); -
2394#endif -
2395 return readBytes;
executed: return readBytes;
Execution Count:133491
133491
2396 -
2397} -
2398 -
2399/*! \reimp -
2400*/ -
2401qint64 QAbstractSocket::readLineData(char *data, qint64 maxlen) -
2402{ -
2403 return QIODevice::readLineData(data, maxlen);
executed: return QIODevice::readLineData(data, maxlen);
Execution Count:4
4
2404} -
2405 -
2406/*! \reimp -
2407*/ -
2408qint64 QAbstractSocket::writeData(const char *data, qint64 size) -
2409{ -
2410 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
2411 if (d->state == QAbstractSocket::UnconnectedState) {
evaluated: d->state == QAbstractSocket::UnconnectedState
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:1297023
6-1297023
2412 d->socketError = QAbstractSocket::UnknownSocketError;
executed (the execution status of this line is deduced): d->socketError = QAbstractSocket::UnknownSocketError;
-
2413 setErrorString(tr("Socket is not connected"));
executed (the execution status of this line is deduced): setErrorString(tr("Socket is not connected"));
-
2414 return -1;
executed: return -1;
Execution Count:6
6
2415 } -
2416 -
2417 if (!d->isBuffered && d->socketType == TcpSocket && d->writeBuffer.isEmpty()) {
evaluated: !d->isBuffered
TRUEFALSE
yes
Evaluation Count:1273904
yes
Evaluation Count:23119
evaluated: d->socketType == TcpSocket
TRUEFALSE
yes
Evaluation Count:1884
yes
Evaluation Count:1272020
evaluated: d->writeBuffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:784
yes
Evaluation Count:1100
784-1273904
2418 // This code is for the new Unbuffered QTcpSocket use case -
2419 qint64 written = d->socketEngine->write(data, size);
executed (the execution status of this line is deduced): qint64 written = d->socketEngine->write(data, size);
-
2420 if (written < 0) {
partially evaluated: written < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:784
0-784
2421 d->socketError = d->socketEngine->error();
never executed (the execution status of this line is deduced): d->socketError = d->socketEngine->error();
-
2422 setErrorString(d->socketEngine->errorString());
never executed (the execution status of this line is deduced): setErrorString(d->socketEngine->errorString());
-
2423 return written;
never executed: return written;
0
2424 } else if (written < size) {
evaluated: written < size
TRUEFALSE
yes
Evaluation Count:45
yes
Evaluation Count:739
45-739
2425 // Buffer what was not written yet -
2426 char *ptr = d->writeBuffer.reserve(size - written);
executed (the execution status of this line is deduced): char *ptr = d->writeBuffer.reserve(size - written);
-
2427 memcpy(ptr, data + written, size - written);
executed (the execution status of this line is deduced): memcpy(ptr, data + written, size - written);
-
2428 if (d->socketEngine)
partially evaluated: d->socketEngine
TRUEFALSE
yes
Evaluation Count:45
no
Evaluation Count:0
0-45
2429 d->socketEngine->setWriteNotificationEnabled(true);
executed: d->socketEngine->setWriteNotificationEnabled(true);
Execution Count:45
45
2430 }
executed: }
Execution Count:45
45
2431 return size; // size=actually written + what has been buffered
executed: return size;
Execution Count:784
784
2432 } else if (!d->isBuffered && d->socketType != TcpSocket) {
evaluated: !d->isBuffered
TRUEFALSE
yes
Evaluation Count:1273120
yes
Evaluation Count:23119
evaluated: d->socketType != TcpSocket
TRUEFALSE
yes
Evaluation Count:1272020
yes
Evaluation Count:1100
1100-1273120
2433 // This is for a QUdpSocket that was connect()ed -
2434 qint64 written = d->socketEngine->write(data, size);
executed (the execution status of this line is deduced): qint64 written = d->socketEngine->write(data, size);
-
2435 if (written < 0) {
partially evaluated: written < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1272020
0-1272020
2436 d->socketError = d->socketEngine->error();
never executed (the execution status of this line is deduced): d->socketError = d->socketEngine->error();
-
2437 setErrorString(d->socketEngine->errorString());
never executed (the execution status of this line is deduced): setErrorString(d->socketEngine->errorString());
-
2438 } else if (!d->writeBuffer.isEmpty()) {
never executed: }
partially evaluated: !d->writeBuffer.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1272020
0-1272020
2439 d->socketEngine->setWriteNotificationEnabled(true);
never executed (the execution status of this line is deduced): d->socketEngine->setWriteNotificationEnabled(true);
-
2440 }
never executed: }
0
2441 -
2442#if defined (QABSTRACTSOCKET_DEBUG) -
2443 qDebug("QAbstractSocket::writeData(%p \"%s\", %lli) == %lli", data, -
2444 qt_prettyDebug(data, qMin((int)size, 32), size).data(), -
2445 size, written); -
2446#endif -
2447 if (written >= 0)
partially evaluated: written >= 0
TRUEFALSE
yes
Evaluation Count:1272020
no
Evaluation Count:0
0-1272020
2448 emit bytesWritten(written);
executed: bytesWritten(written);
Execution Count:1272020
1272020
2449 return written;
executed: return written;
Execution Count:1272020
1272020
2450 } -
2451 -
2452 // This is the code path for normal buffered QTcpSocket or -
2453 // unbuffered QTcpSocket when there was already something in the -
2454 // write buffer and therefore we could not do a direct engine write. -
2455 // We just write to our write buffer and enable the write notifier -
2456 // The write notifier then flush()es the buffer. -
2457 -
2458 char *ptr = d->writeBuffer.reserve(size);
executed (the execution status of this line is deduced): char *ptr = d->writeBuffer.reserve(size);
-
2459 if (size == 1)
evaluated: size == 1
TRUEFALSE
yes
Evaluation Count:11226
yes
Evaluation Count:12993
11226-12993
2460 *ptr = *data;
executed: *ptr = *data;
Execution Count:11226
11226
2461 else -
2462 memcpy(ptr, data, size);
executed: memcpy(ptr, data, size);
Execution Count:12993
12993
2463 -
2464 qint64 written = size;
executed (the execution status of this line is deduced): qint64 written = size;
-
2465 -
2466 if (d->socketEngine && !d->writeBuffer.isEmpty())
partially evaluated: d->socketEngine
TRUEFALSE
yes
Evaluation Count:24219
no
Evaluation Count:0
evaluated: !d->writeBuffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:24206
yes
Evaluation Count:13
0-24219
2467 d->socketEngine->setWriteNotificationEnabled(true);
executed: d->socketEngine->setWriteNotificationEnabled(true);
Execution Count:24206
24206
2468 -
2469#if defined (QABSTRACTSOCKET_DEBUG) -
2470 qDebug("QAbstractSocket::writeData(%p \"%s\", %lli) == %lli", data, -
2471 qt_prettyDebug(data, qMin((int)size, 32), size).data(), -
2472 size, written); -
2473#endif -
2474 return written;
executed: return written;
Execution Count:24219
24219
2475} -
2476 -
2477/*! -
2478 \since 4.1 -
2479 -
2480 Sets the port on the local side of a connection to \a port. -
2481 -
2482 You can call this function in a subclass of QAbstractSocket to -
2483 change the return value of the localPort() function after a -
2484 connection has been established. This feature is commonly used by -
2485 proxy connections for virtual connection settings. -
2486 -
2487 Note that this function does not bind the local port of the socket -
2488 prior to a connection (e.g., QAbstractSocket::bind()). -
2489 -
2490 \sa localAddress(), setLocalAddress(), setPeerPort() -
2491*/ -
2492void QAbstractSocket::setLocalPort(quint16 port) -
2493{ -
2494 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
2495 d->localPort = port;
executed (the execution status of this line is deduced): d->localPort = port;
-
2496}
executed: }
Execution Count:229
229
2497 -
2498/*! -
2499 \since 4.1 -
2500 -
2501 Sets the address on the local side of a connection to -
2502 \a address. -
2503 -
2504 You can call this function in a subclass of QAbstractSocket to -
2505 change the return value of the localAddress() function after a -
2506 connection has been established. This feature is commonly used by -
2507 proxy connections for virtual connection settings. -
2508 -
2509 Note that this function does not bind the local address of the socket -
2510 prior to a connection (e.g., QAbstractSocket::bind()). -
2511 -
2512 \sa localAddress(), setLocalPort(), setPeerAddress() -
2513*/ -
2514void QAbstractSocket::setLocalAddress(const QHostAddress &address) -
2515{ -
2516 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
2517 d->localAddress = address;
executed (the execution status of this line is deduced): d->localAddress = address;
-
2518}
executed: }
Execution Count:227
227
2519 -
2520/*! -
2521 \since 4.1 -
2522 -
2523 Sets the port of the remote side of the connection to -
2524 \a port. -
2525 -
2526 You can call this function in a subclass of QAbstractSocket to -
2527 change the return value of the peerPort() function after a -
2528 connection has been established. This feature is commonly used by -
2529 proxy connections for virtual connection settings. -
2530 -
2531 \sa peerPort(), setPeerAddress(), setLocalPort() -
2532*/ -
2533void QAbstractSocket::setPeerPort(quint16 port) -
2534{ -
2535 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
2536 d->peerPort = port;
executed (the execution status of this line is deduced): d->peerPort = port;
-
2537}
executed: }
Execution Count:229
229
2538 -
2539/*! -
2540 \since 4.1 -
2541 -
2542 Sets the address of the remote side of the connection -
2543 to \a address. -
2544 -
2545 You can call this function in a subclass of QAbstractSocket to -
2546 change the return value of the peerAddress() function after a -
2547 connection has been established. This feature is commonly used by -
2548 proxy connections for virtual connection settings. -
2549 -
2550 \sa peerAddress(), setPeerPort(), setLocalAddress() -
2551*/ -
2552void QAbstractSocket::setPeerAddress(const QHostAddress &address) -
2553{ -
2554 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
2555 d->peerAddress = address;
executed (the execution status of this line is deduced): d->peerAddress = address;
-
2556}
executed: }
Execution Count:227
227
2557 -
2558/*! -
2559 \since 4.1 -
2560 -
2561 Sets the host name of the remote peer to \a name. -
2562 -
2563 You can call this function in a subclass of QAbstractSocket to -
2564 change the return value of the peerName() function after a -
2565 connection has been established. This feature is commonly used by -
2566 proxy connections for virtual connection settings. -
2567 -
2568 \sa peerName() -
2569*/ -
2570void QAbstractSocket::setPeerName(const QString &name) -
2571{ -
2572 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
2573 d->peerName = name;
executed (the execution status of this line is deduced): d->peerName = name;
-
2574}
executed: }
Execution Count:227
227
2575 -
2576/*! -
2577 Closes the I/O device for the socket, disconnects the socket's connection with the -
2578 host, closes the socket, and resets the name, address, port number and underlying -
2579 socket descriptor. -
2580 -
2581 See QIODevice::close() for a description of the actions that occur when an I/O -
2582 device is closed. -
2583 -
2584 \sa abort() -
2585*/ -
2586void QAbstractSocket::close() -
2587{ -
2588 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
2589#if defined(QABSTRACTSOCKET_DEBUG) -
2590 qDebug("QAbstractSocket::close()"); -
2591#endif -
2592 QIODevice::close();
executed (the execution status of this line is deduced): QIODevice::close();
-
2593 if (d->state != UnconnectedState) {
evaluated: d->state != UnconnectedState
TRUEFALSE
yes
Evaluation Count:2637
yes
Evaluation Count:563
563-2637
2594 d->closeCalled = true;
executed (the execution status of this line is deduced): d->closeCalled = true;
-
2595 disconnectFromHost();
executed (the execution status of this line is deduced): disconnectFromHost();
-
2596 }
executed: }
Execution Count:2637
2637
2597 -
2598 d->localPort = 0;
executed (the execution status of this line is deduced): d->localPort = 0;
-
2599 d->peerPort = 0;
executed (the execution status of this line is deduced): d->peerPort = 0;
-
2600 d->localAddress.clear();
executed (the execution status of this line is deduced): d->localAddress.clear();
-
2601 d->peerAddress.clear();
executed (the execution status of this line is deduced): d->peerAddress.clear();
-
2602 d->peerName.clear();
executed (the execution status of this line is deduced): d->peerName.clear();
-
2603 d->cachedSocketDescriptor = -1;
executed (the execution status of this line is deduced): d->cachedSocketDescriptor = -1;
-
2604}
executed: }
Execution Count:3200
3200
2605 -
2606/*! -
2607 Attempts to close the socket. If there is pending data waiting to -
2608 be written, QAbstractSocket will enter ClosingState and wait -
2609 until all data has been written. Eventually, it will enter -
2610 UnconnectedState and emit the disconnected() signal. -
2611 -
2612 \sa connectToHost() -
2613*/ -
2614void QAbstractSocket::disconnectFromHost() -
2615{ -
2616 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
2617#if defined(QABSTRACTSOCKET_DEBUG) -
2618 qDebug("QAbstractSocket::disconnectFromHost()"); -
2619#endif -
2620 -
2621 if (d->state == UnconnectedState) {
evaluated: d->state == UnconnectedState
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:3168
6-3168
2622#if defined(QABSTRACTSOCKET_DEBUG) -
2623 qDebug("QAbstractSocket::disconnectFromHost() was called on an unconnected socket"); -
2624#endif -
2625 return;
executed: return;
Execution Count:6
6
2626 } -
2627 -
2628 if (!d->abortCalled && (d->state == ConnectingState || d->state == HostLookupState)) {
evaluated: !d->abortCalled
TRUEFALSE
yes
Evaluation Count:1509
yes
Evaluation Count:1659
evaluated: d->state == ConnectingState
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:1506
partially evaluated: d->state == HostLookupState
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1506
0-1659
2629#if defined(QABSTRACTSOCKET_DEBUG) -
2630 qDebug("QAbstractSocket::disconnectFromHost() but we're still connecting"); -
2631#endif -
2632 d->pendingClose = true;
executed (the execution status of this line is deduced): d->pendingClose = true;
-
2633 return;
executed: return;
Execution Count:3
3
2634 } -
2635 -
2636 // Disable and delete read notification -
2637 if (d->socketEngine)
evaluated: d->socketEngine
TRUEFALSE
yes
Evaluation Count:2842
yes
Evaluation Count:323
323-2842
2638 d->socketEngine->setReadNotificationEnabled(false);
executed: d->socketEngine->setReadNotificationEnabled(false);
Execution Count:2842
2842
2639 -
2640 if (d->abortCalled) {
evaluated: d->abortCalled
TRUEFALSE
yes
Evaluation Count:1659
yes
Evaluation Count:1506
1506-1659
2641#if defined(QABSTRACTSOCKET_DEBUG) -
2642 qDebug("QAbstractSocket::disconnectFromHost() aborting immediately"); -
2643#endif -
2644 if (d->state == HostLookupState) {
evaluated: d->state == HostLookupState
TRUEFALSE
yes
Evaluation Count:118
yes
Evaluation Count:1541
118-1541
2645 QHostInfo::abortHostLookup(d->hostLookupId);
executed (the execution status of this line is deduced): QHostInfo::abortHostLookup(d->hostLookupId);
-
2646 d->hostLookupId = -1;
executed (the execution status of this line is deduced): d->hostLookupId = -1;
-
2647 }
executed: }
Execution Count:118
118
2648 } else {
executed: }
Execution Count:1659
1659
2649 // Perhaps emit closing() -
2650 if (d->state != ClosingState) {
evaluated: d->state != ClosingState
TRUEFALSE
yes
Evaluation Count:1362
yes
Evaluation Count:144
144-1362
2651 d->state = ClosingState;
executed (the execution status of this line is deduced): d->state = ClosingState;
-
2652#if defined(QABSTRACTSOCKET_DEBUG) -
2653 qDebug("QAbstractSocket::disconnectFromHost() emits stateChanged()(ClosingState)"); -
2654#endif -
2655 emit stateChanged(d->state);
executed (the execution status of this line is deduced): stateChanged(d->state);
-
2656 } else {
executed: }
Execution Count:1362
1362
2657#if defined(QABSTRACTSOCKET_DEBUG) -
2658 qDebug("QAbstractSocket::disconnectFromHost() return from delayed close"); -
2659#endif -
2660 }
executed: }
Execution Count:144
144
2661 -
2662 // Wait for pending data to be written. -
2663 if (d->socketEngine && d->socketEngine->isValid() && (d->writeBuffer.size() > 0
evaluated: d->socketEngine
TRUEFALSE
yes
Evaluation Count:1301
yes
Evaluation Count:205
partially evaluated: d->socketEngine->isValid()
TRUEFALSE
yes
Evaluation Count:1301
no
Evaluation Count:0
evaluated: d->writeBuffer.size() > 0
TRUEFALSE
yes
Evaluation Count:147
yes
Evaluation Count:1154
0-1301
2664 || d->socketEngine->bytesToWrite() > 0)) {
partially evaluated: d->socketEngine->bytesToWrite() > 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1154
0-1154
2665 // hack: when we are waiting for the socket engine to write bytes (only -
2666 // possible when using Socks5 or HTTP socket engine), then close -
2667 // anyway after 2 seconds. This is to prevent a timeout on Mac, where we -
2668 // sometimes just did not get the write notifier from the underlying -
2669 // CFSocket and no progress was made. -
2670 if (d->writeBuffer.size() == 0 && d->socketEngine->bytesToWrite() > 0) {
partially evaluated: d->writeBuffer.size() == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:147
never evaluated: d->socketEngine->bytesToWrite() > 0
0-147
2671 if (!d->disconnectTimer) {
never evaluated: !d->disconnectTimer
0
2672 d->disconnectTimer = new QTimer(this);
never executed (the execution status of this line is deduced): d->disconnectTimer = new QTimer(this);
-
2673 connect(d->disconnectTimer, SIGNAL(timeout()), this,
never executed (the execution status of this line is deduced): connect(d->disconnectTimer, "2""timeout()", this,
-
2674 SLOT(_q_forceDisconnect()), Qt::DirectConnection);
never executed (the execution status of this line is deduced): "1""_q_forceDisconnect()", Qt::DirectConnection);
-
2675 }
never executed: }
0
2676 if (!d->disconnectTimer->isActive())
never evaluated: !d->disconnectTimer->isActive()
0
2677 d->disconnectTimer->start(2000);
never executed: d->disconnectTimer->start(2000);
0
2678 }
never executed: }
0
2679 d->socketEngine->setWriteNotificationEnabled(true);
executed (the execution status of this line is deduced): d->socketEngine->setWriteNotificationEnabled(true);
-
2680 -
2681#if defined(QABSTRACTSOCKET_DEBUG) -
2682 qDebug("QAbstractSocket::disconnectFromHost() delaying disconnect"); -
2683#endif -
2684 return;
executed: return;
Execution Count:147
147
2685 } else { -
2686#if defined(QABSTRACTSOCKET_DEBUG) -
2687 qDebug("QAbstractSocket::disconnectFromHost() disconnecting immediately"); -
2688#endif -
2689 }
executed: }
Execution Count:1359
1359
2690 } -
2691 -
2692 SocketState previousState = d->state;
executed (the execution status of this line is deduced): SocketState previousState = d->state;
-
2693 d->resetSocketLayer();
executed (the execution status of this line is deduced): d->resetSocketLayer();
-
2694 d->state = UnconnectedState;
executed (the execution status of this line is deduced): d->state = UnconnectedState;
-
2695 emit stateChanged(d->state);
executed (the execution status of this line is deduced): stateChanged(d->state);
-
2696 emit readChannelFinished(); // we got an EOF
executed (the execution status of this line is deduced): readChannelFinished();
-
2697 -
2698 // only emit disconnected if we were connected before -
2699 if (previousState == ConnectedState || previousState == ClosingState)
evaluated: previousState == ConnectedState
TRUEFALSE
yes
Evaluation Count:422
yes
Evaluation Count:2596
evaluated: previousState == ClosingState
TRUEFALSE
yes
Evaluation Count:1362
yes
Evaluation Count:1234
422-2596
2700 emit disconnected();
executed: disconnected();
Execution Count:1784
1784
2701 -
2702 d->localPort = 0;
executed (the execution status of this line is deduced): d->localPort = 0;
-
2703 d->peerPort = 0;
executed (the execution status of this line is deduced): d->peerPort = 0;
-
2704 d->localAddress.clear();
executed (the execution status of this line is deduced): d->localAddress.clear();
-
2705 d->peerAddress.clear();
executed (the execution status of this line is deduced): d->peerAddress.clear();
-
2706 -
2707#if defined(QABSTRACTSOCKET_DEBUG) -
2708 qDebug("QAbstractSocket::disconnectFromHost() disconnected!"); -
2709#endif -
2710 -
2711 if (d->closeCalled) {
evaluated: d->closeCalled
TRUEFALSE
yes
Evaluation Count:2629
yes
Evaluation Count:389
389-2629
2712#if defined(QABSTRACTSOCKET_DEBUG) -
2713 qDebug("QAbstractSocket::disconnectFromHost() closed!"); -
2714#endif -
2715 d->buffer.clear();
executed (the execution status of this line is deduced): d->buffer.clear();
-
2716 d->writeBuffer.clear();
executed (the execution status of this line is deduced): d->writeBuffer.clear();
-
2717 QIODevice::close();
executed (the execution status of this line is deduced): QIODevice::close();
-
2718 }
executed: }
Execution Count:2629
2629
2719}
executed: }
Execution Count:3018
3018
2720 -
2721/*! -
2722 Returns the size of the internal read buffer. This limits the -
2723 amount of data that the client can receive before you call read() -
2724 or readAll(). -
2725 -
2726 A read buffer size of 0 (the default) means that the buffer has -
2727 no size limit, ensuring that no data is lost. -
2728 -
2729 \sa setReadBufferSize(), read() -
2730*/ -
2731qint64 QAbstractSocket::readBufferSize() const -
2732{ -
2733 return d_func()->readBufferMaxSize;
executed: return d_func()->readBufferMaxSize;
Execution Count:19
19
2734} -
2735 -
2736/*! -
2737 Sets the size of QAbstractSocket's internal read buffer to be \a -
2738 size bytes. -
2739 -
2740 If the buffer size is limited to a certain size, QAbstractSocket -
2741 won't buffer more than this size of data. Exceptionally, a buffer -
2742 size of 0 means that the read buffer is unlimited and all -
2743 incoming data is buffered. This is the default. -
2744 -
2745 This option is useful if you only read the data at certain points -
2746 in time (e.g., in a real-time streaming application) or if you -
2747 want to protect your socket against receiving too much data, -
2748 which may eventually cause your application to run out of memory. -
2749 -
2750 Only QTcpSocket uses QAbstractSocket's internal buffer; QUdpSocket -
2751 does not use any buffering at all, but rather relies on the -
2752 implicit buffering provided by the operating system. -
2753 Because of this, calling this function on QUdpSocket has no -
2754 effect. -
2755 -
2756 \sa readBufferSize(), read() -
2757*/ -
2758void QAbstractSocket::setReadBufferSize(qint64 size) -
2759{ -
2760 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
2761 -
2762 if (d->readBufferMaxSize == size)
evaluated: d->readBufferMaxSize == size
TRUEFALSE
yes
Evaluation Count:292
yes
Evaluation Count:604
292-604
2763 return;
executed: return;
Execution Count:292
292
2764 d->readBufferMaxSize = size;
executed (the execution status of this line is deduced): d->readBufferMaxSize = size;
-
2765 if (!d->readSocketNotifierCalled && d->socketEngine) {
partially evaluated: !d->readSocketNotifierCalled
TRUEFALSE
yes
Evaluation Count:604
no
Evaluation Count:0
evaluated: d->socketEngine
TRUEFALSE
yes
Evaluation Count:535
yes
Evaluation Count:69
0-604
2766 // ensure that the read notification is enabled if we've now got -
2767 // room in the read buffer -
2768 // but only if we're not inside canReadNotification -- that will take care on its own -
2769 if ((size == 0 || d->buffer.size() < size) && d->state == QAbstractSocket::ConnectedState) // Do not change the notifier unless we are connected.
evaluated: size == 0
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:533
partially evaluated: d->buffer.size() < size
TRUEFALSE
yes
Evaluation Count:533
no
Evaluation Count:0
evaluated: d->state == QAbstractSocket::ConnectedState
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:531
0-533
2770 d->socketEngine->setReadNotificationEnabled(true);
executed: d->socketEngine->setReadNotificationEnabled(true);
Execution Count:4
4
2771 }
executed: }
Execution Count:535
535
2772}
executed: }
Execution Count:604
604
2773 -
2774/*! -
2775 Returns the state of the socket. -
2776 -
2777 \sa error() -
2778*/ -
2779QAbstractSocket::SocketState QAbstractSocket::state() const -
2780{ -
2781 return d_func()->state;
executed: return d_func()->state;
Execution Count:431140
431140
2782} -
2783 -
2784/*! -
2785 Sets the state of the socket to \a state. -
2786 -
2787 \sa state() -
2788*/ -
2789void QAbstractSocket::setSocketState(SocketState state) -
2790{ -
2791 d_func()->state = state;
executed (the execution status of this line is deduced): d_func()->state = state;
-
2792}
executed: }
Execution Count:830
830
2793 -
2794/*! -
2795 Returns the socket type (TCP, UDP, or other). -
2796 -
2797 \sa QTcpSocket, QUdpSocket -
2798*/ -
2799QAbstractSocket::SocketType QAbstractSocket::socketType() const -
2800{ -
2801 return d_func()->socketType;
executed: return d_func()->socketType;
Execution Count:4930
4930
2802} -
2803 -
2804/*! -
2805 Returns the type of error that last occurred. -
2806 -
2807 \sa state(), errorString() -
2808*/ -
2809QAbstractSocket::SocketError QAbstractSocket::error() const -
2810{ -
2811 return d_func()->socketError;
executed: return d_func()->socketError;
Execution Count:145
145
2812} -
2813 -
2814/*! -
2815 Sets the type of error that last occurred to \a socketError. -
2816 -
2817 \sa setSocketState(), setErrorString() -
2818*/ -
2819void QAbstractSocket::setSocketError(SocketError socketError) -
2820{ -
2821 d_func()->socketError = socketError;
executed (the execution status of this line is deduced): d_func()->socketError = socketError;
-
2822}
executed: }
Execution Count:176
176
2823 -
2824#ifndef QT_NO_NETWORKPROXY -
2825/*! -
2826 \since 4.1 -
2827 -
2828 Sets the explicit network proxy for this socket to \a networkProxy. -
2829 -
2830 To disable the use of a proxy for this socket, use the -
2831 QNetworkProxy::NoProxy proxy type: -
2832 -
2833 \snippet code/src_network_socket_qabstractsocket.cpp 3 -
2834 -
2835 The default value for the proxy is QNetworkProxy::DefaultProxy, -
2836 which means the socket will use the application settings: if a -
2837 proxy is set with QNetworkProxy::setApplicationProxy, it will use -
2838 that; otherwise, if a factory is set with -
2839 QNetworkProxyFactory::setApplicationProxyFactory, it will query -
2840 that factory with type QNetworkProxyQuery::TcpSocket. -
2841 -
2842 \sa proxy(), QNetworkProxy, QNetworkProxyFactory::queryProxy() -
2843*/ -
2844void QAbstractSocket::setProxy(const QNetworkProxy &networkProxy) -
2845{ -
2846 Q_D(QAbstractSocket);
executed (the execution status of this line is deduced): QAbstractSocketPrivate * const d = d_func();
-
2847 d->proxy = networkProxy;
executed (the execution status of this line is deduced): d->proxy = networkProxy;
-
2848}
executed: }
Execution Count:976
976
2849 -
2850/*! -
2851 \since 4.1 -
2852 -
2853 Returns the network proxy for this socket. -
2854 By default QNetworkProxy::DefaultProxy is used, which means this -
2855 socket will query the default proxy settings for the application. -
2856 -
2857 \sa setProxy(), QNetworkProxy, QNetworkProxyFactory -
2858*/ -
2859QNetworkProxy QAbstractSocket::proxy() const -
2860{ -
2861 Q_D(const QAbstractSocket);
executed (the execution status of this line is deduced): const QAbstractSocketPrivate * const d = d_func();
-
2862 return d->proxy;
executed: return d->proxy;
Execution Count:2475
2475
2863} -
2864#endif // QT_NO_NETWORKPROXY -
2865 -
2866#ifndef QT_NO_DEBUG_STREAM -
2867Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, QAbstractSocket::SocketError error) -
2868{ -
2869 switch (error) { -
2870 case QAbstractSocket::ConnectionRefusedError: -
2871 debug << "QAbstractSocket::ConnectionRefusedError";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::ConnectionRefusedError";
-
2872 break;
never executed: break;
0
2873 case QAbstractSocket::RemoteHostClosedError: -
2874 debug << "QAbstractSocket::RemoteHostClosedError";
executed (the execution status of this line is deduced): debug << "QAbstractSocket::RemoteHostClosedError";
-
2875 break;
executed: break;
Execution Count:23
23
2876 case QAbstractSocket::HostNotFoundError: -
2877 debug << "QAbstractSocket::HostNotFoundError";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::HostNotFoundError";
-
2878 break;
never executed: break;
0
2879 case QAbstractSocket::SocketAccessError: -
2880 debug << "QAbstractSocket::SocketAccessError";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::SocketAccessError";
-
2881 break;
never executed: break;
0
2882 case QAbstractSocket::SocketResourceError: -
2883 debug << "QAbstractSocket::SocketResourceError";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::SocketResourceError";
-
2884 break;
never executed: break;
0
2885 case QAbstractSocket::SocketTimeoutError: -
2886 debug << "QAbstractSocket::SocketTimeoutError";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::SocketTimeoutError";
-
2887 break;
never executed: break;
0
2888 case QAbstractSocket::DatagramTooLargeError: -
2889 debug << "QAbstractSocket::DatagramTooLargeError";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::DatagramTooLargeError";
-
2890 break;
never executed: break;
0
2891 case QAbstractSocket::NetworkError: -
2892 debug << "QAbstractSocket::NetworkError";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::NetworkError";
-
2893 break;
never executed: break;
0
2894 case QAbstractSocket::AddressInUseError: -
2895 debug << "QAbstractSocket::AddressInUseError";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::AddressInUseError";
-
2896 break;
never executed: break;
0
2897 case QAbstractSocket::SocketAddressNotAvailableError: -
2898 debug << "QAbstractSocket::SocketAddressNotAvailableError";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::SocketAddressNotAvailableError";
-
2899 break;
never executed: break;
0
2900 case QAbstractSocket::UnsupportedSocketOperationError: -
2901 debug << "QAbstractSocket::UnsupportedSocketOperationError";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::UnsupportedSocketOperationError";
-
2902 break;
never executed: break;
0
2903 case QAbstractSocket::UnfinishedSocketOperationError: -
2904 debug << "QAbstractSocket::UnfinishedSocketOperationError";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::UnfinishedSocketOperationError";
-
2905 break;
never executed: break;
0
2906 case QAbstractSocket::ProxyAuthenticationRequiredError: -
2907 debug << "QAbstractSocket::ProxyAuthenticationRequiredError";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::ProxyAuthenticationRequiredError";
-
2908 break;
never executed: break;
0
2909 case QAbstractSocket::UnknownSocketError: -
2910 debug << "QAbstractSocket::UnknownSocketError";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::UnknownSocketError";
-
2911 break;
never executed: break;
0
2912 case QAbstractSocket::ProxyConnectionRefusedError: -
2913 debug << "QAbstractSocket::ProxyConnectionRefusedError";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::ProxyConnectionRefusedError";
-
2914 break;
never executed: break;
0
2915 case QAbstractSocket::ProxyConnectionClosedError: -
2916 debug << "QAbstractSocket::ProxyConnectionClosedError";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::ProxyConnectionClosedError";
-
2917 break;
never executed: break;
0
2918 case QAbstractSocket::ProxyConnectionTimeoutError: -
2919 debug << "QAbstractSocket::ProxyConnectionTimeoutError";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::ProxyConnectionTimeoutError";
-
2920 break;
never executed: break;
0
2921 case QAbstractSocket::ProxyNotFoundError: -
2922 debug << "QAbstractSocket::ProxyNotFoundError";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::ProxyNotFoundError";
-
2923 break;
never executed: break;
0
2924 case QAbstractSocket::ProxyProtocolError: -
2925 debug << "QAbstractSocket::ProxyProtocolError";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::ProxyProtocolError";
-
2926 break;
never executed: break;
0
2927 default: -
2928 debug << "QAbstractSocket::SocketError(" << int(error) << ')';
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::SocketError(" << int(error) << ')';
-
2929 break;
never executed: break;
0
2930 } -
2931 return debug;
executed: return debug;
Execution Count:23
23
2932} -
2933 -
2934Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, QAbstractSocket::SocketState state) -
2935{ -
2936 switch (state) { -
2937 case QAbstractSocket::UnconnectedState: -
2938 debug << "QAbstractSocket::UnconnectedState";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::UnconnectedState";
-
2939 break;
never executed: break;
0
2940 case QAbstractSocket::HostLookupState: -
2941 debug << "QAbstractSocket::HostLookupState";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::HostLookupState";
-
2942 break;
never executed: break;
0
2943 case QAbstractSocket::ConnectingState: -
2944 debug << "QAbstractSocket::ConnectingState";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::ConnectingState";
-
2945 break;
never executed: break;
0
2946 case QAbstractSocket::ConnectedState: -
2947 debug << "QAbstractSocket::ConnectedState";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::ConnectedState";
-
2948 break;
never executed: break;
0
2949 case QAbstractSocket::BoundState: -
2950 debug << "QAbstractSocket::BoundState";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::BoundState";
-
2951 break;
never executed: break;
0
2952 case QAbstractSocket::ListeningState: -
2953 debug << "QAbstractSocket::ListeningState";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::ListeningState";
-
2954 break;
never executed: break;
0
2955 case QAbstractSocket::ClosingState: -
2956 debug << "QAbstractSocket::ClosingState";
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::ClosingState";
-
2957 break;
never executed: break;
0
2958 default: -
2959 debug << "QAbstractSocket::SocketState(" << int(state) << ')';
never executed (the execution status of this line is deduced): debug << "QAbstractSocket::SocketState(" << int(state) << ')';
-
2960 break;
never executed: break;
0
2961 } -
2962 return debug;
never executed: return debug;
0
2963} -
2964#endif -
2965 -
2966QT_END_NAMESPACE -
2967 -
2968#include "moc_qabstractsocket.cpp" -
2969 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial