qnetworksession.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/network/bearer/qnetworksession.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtNetwork module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qnetworksession.h"-
35#include "qnetworksession_p.h"-
36#include "qbearerengine_p.h"-
37-
38#include <QEventLoop>-
39#include <QMetaMethod>-
40#include <QTimer>-
41#include <QThread>-
42-
43#include "qnetworkconfigmanager_p.h"-
44-
45// for QNetworkSession::interface-
46#ifdef interface-
47# undef interface-
48#endif-
49-
50#ifndef QT_NO_BEARERMANAGEMENT-
51-
52QT_BEGIN_NAMESPACE-
53-
54/*!-
55 \class QNetworkSession-
56-
57 \brief The QNetworkSession class provides control over the system's access points-
58 and enables session management for cases when multiple clients access the same access point.-
59-
60 \since 4.7-
61-
62 \inmodule QtNetwork-
63 \ingroup network-
64-
65 A QNetworkSession enables control over the system's network interfaces. The session's configuration-
66 parameter are determined via the QNetworkConfiguration object to which it is bound. Depending on the-
67 type of the session (single access point or service network) a session may be linked to one or more-
68 network interfaces. By means of \l{open()}{opening} and \l{close()}{closing} of network sessions-
69 a developer can start and stop the systems network interfaces. If the configuration represents-
70 multiple access points (see \l QNetworkConfiguration::ServiceNetwork) more advanced features such as roaming may be supported.-
71-
72 QNetworkSession supports session management within the same process and depending on the platform's-
73 capabilities may support out-of-process sessions. If the same-
74 network configuration is used by multiple open sessions the underlying network interface is only terminated once-
75 the last session has been closed.-
76-
77 \section1 Roaming-
78-
79 Applications may connect to the preferredConfigurationChanged() signal in order to-
80 receive notifications when a more suitable access point becomes available.-
81 In response to this signal the application must either initiate the roaming via migrate()-
82 or ignore() the new access point. Once the session has roamed the-
83 newConfigurationActivated() signal is emitted. The application may now test the-
84 carrier and must either accept() or reject() it. The session will return to the previous-
85 access point if the roaming was rejected. The subsequent state diagram depicts the required-
86 state transitions.-
87-
88 \image roaming-states.png-
89-
90 Some platforms may distinguish forced roaming and application level roaming (ALR).-
91 ALR implies that the application controls (via migrate(), ignore(), accept() and reject())-
92 whether a network session can roam from one access point to the next. Such control is useful-
93 if the application maintains stateful socket connections and wants to control the transition from-
94 one interface to the next. Forced roaming implies that the system automatically roams to the next network without-
95 consulting the application. This has the advantage that the application can make use of roaming features-
96 without actually being aware of it. It is expected that the application detects that the underlying-
97 socket is broken and automatically reconnects via the new network link.-
98-
99 If the platform supports both modes of roaming, an application indicates its preference-
100 by connecting to the preferredConfigurationChanged() signal. Connecting to this signal means that-
101 the application wants to take control over the roaming behavior and therefore implies application-
102 level roaming. If the client does not connect to the preferredConfigurationChanged(), forced roaming-
103 is used. If forced roaming is not supported the network session will not roam by default.-
104-
105 Some applications may want to suppress any form of roaming altogether. Possible use cases may be-
106 high priority downloads or remote services which cannot handle a roaming enabled client. Clients-
107 can suppress roaming by connecting to the preferredConfigurationChanged() signal and answer each-
108 signal emission with ignore().-
109-
110 \sa QNetworkConfiguration, QNetworkConfigurationManager-
111*/-
112-
113/*!-
114 \enum QNetworkSession::State-
115-
116 This enum describes the connectivity state of the session. If the session is based on a-
117 single access point configuration the state of the session is the same as the state of the-
118 associated network interface.-
119-
120 \value Invalid The session is invalid due to an invalid configuration. This may-
121 happen due to a removed access point or a configuration that was-
122 invalid to begin with.-
123 \value NotAvailable The session is based on a defined but not yet discovered QNetworkConfiguration-
124 (see \l QNetworkConfiguration::StateFlag).-
125 \value Connecting The network session is being established.-
126 \value Connected The network session is connected. If the current process wishes to use this session-
127 it has to register its interest by calling open(). A network session-
128 is considered to be ready for socket operations if it isOpen() and connected.-
129 \value Closing The network session is in the process of being shut down.-
130 \value Disconnected The network session is not connected. The associated QNetworkConfiguration-
131 has the state QNetworkConfiguration::Discovered.-
132 \value Roaming The network session is roaming from one access point to another-
133 access point.-
134*/-
135-
136/*!-
137 \enum QNetworkSession::SessionError-
138-
139 This enum describes the session errors that can occur.-
140-
141 \value UnknownSessionError An unidentified error occurred.-
142 \value SessionAbortedError The session was aborted by the user or system.-
143 \value RoamingError The session cannot roam to a new configuration.-
144 \value OperationNotSupportedError The operation is not supported for current configuration.-
145 \value InvalidConfigurationError The operation cannot currently be performed for the-
146 current configuration.-
147*/-
148-
149/*!-
150 \enum QNetworkSession::UsagePolicy-
151 \since 5.0-
152-
153 These flags allow the system to inform the application of network usage restrictions that-
154 may be in place.-
155-
156 \value NoPolicy No policy in force, usage is unrestricted.-
157 \value NoBackgroundTrafficPolicy Background network traffic (not user initiated) should be avoided-
158 for example to save battery or data charges-
159*/-
160-
161/*!-
162 \fn void QNetworkSession::stateChanged(QNetworkSession::State state)-
163-
164 This signal is emitted whenever the state of the network session changes.-
165 The \a state parameter is the new state.-
166-
167 \sa state()-
168*/-
169-
170/*!-
171 \fn void QNetworkSession::error(QNetworkSession::SessionError error)-
172-
173 This signal is emitted after an error occurred. The \a error parameter-
174 describes the error that occurred.-
175-
176 \sa error(), errorString()-
177*/-
178-
179/*!-
180 \fn void QNetworkSession::preferredConfigurationChanged(const QNetworkConfiguration &config, bool isSeamless)-
181-
182 This signal is emitted when the preferred configuration/access point for the-
183 session changes. Only sessions which are based on service network configurations-
184 may emit this signal. \a config can be used to determine access point specific-
185 details such as proxy settings and \a isSeamless indicates whether roaming will-
186 break the sessions IP address.-
187-
188 As a consequence to this signal the application must either start the roaming process-
189 by calling migrate() or choose to ignore() the new access point.-
190-
191 If the roaming process is non-seamless the IP address will change which means that-
192 a socket becomes invalid. However seamless mobility can ensure that the local IP address-
193 does not change. This is achieved by using a virtual IP address which is bound to the actual-
194 link address. During the roaming process the virtual address is attached to the new link-
195 address.-
196-
197 Some platforms may support the concept of Forced Roaming and Application Level Roaming (ALR).-
198 Forced roaming implies that the platform may simply roam to a new configuration without-
199 consulting applications. It is up to the application to detect the link layer loss and reestablish-
200 its sockets. In contrast ALR provides the opportunity to prevent the system from roaming.-
201 If this session is based on a configuration that supports roaming the application can choose-
202 whether it wants to be consulted (ALR use case) by connecting to this signal. For as long as this signal-
203 connection remains the session remains registered as a roaming stakeholder; otherwise roaming will-
204 be enforced by the platform.-
205-
206 \sa migrate(), ignore(), QNetworkConfiguration::isRoamingAvailable()-
207*/-
208-
209/*!-
210 \fn void QNetworkSession::newConfigurationActivated()-
211-
212 This signal is emitted once the session has roamed to the new access point.-
213 The application may reopen its socket and test the suitability of the new network link.-
214 Subsequently it must either accept() or reject() the new access point.-
215-
216 \sa accept(), reject()-
217*/-
218-
219/*!-
220 \fn void QNetworkSession::opened()-
221-
222 This signal is emitted when the network session has been opened.-
223-
224 The underlying network interface will not be shut down as long as the session remains open.-
225 Note that this feature is dependent on \l{QNetworkConfigurationManager::SystemSessionSupport}{system wide session support}.-
226*/-
227-
228/*!-
229 \fn void QNetworkSession::closed()-
230-
231 This signal is emitted when the network session has been closed.-
232*/-
233-
234/*!-
235 \fn void QNetworkSession::usagePoliciesChanged(QNetworkSession::UsagePolicies usagePolicies)-
236 \since 5.0-
237-
238 This signal is emitted when the \a usagePolicies in force are changed by the system.-
239*/-
240-
241/*!-
242 Constructs a session based on \a connectionConfig with the given \a parent.-
243-
244 \sa QNetworkConfiguration-
245*/-
246QNetworkSession::QNetworkSession(const QNetworkConfiguration &connectionConfig, QObject *parent)-
247 : QObject(parent), d(0)-
248{-
249 // invalid configuration-
250 if (!connectionConfig.identifier().isEmpty()) {
!connectionCon...er().isEmpty()Description
TRUEevaluated 78 times by 15 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QHostInfo
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QTcpServer
  • tst_QUdpSocket
  • tst_QXmlInputSource
  • tst_Spdy
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QNetworkSession
2-78
251 foreach (QBearerEngine *engine, qNetworkConfigurationManagerPrivate()->engines()) {-
252 if (engine->hasIdentifier(connectionConfig.identifier())) {
engine->hasIde....identifier())Description
TRUEevaluated 78 times by 15 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QHostInfo
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QTcpServer
  • tst_QUdpSocket
  • tst_QXmlInputSource
  • tst_Spdy
FALSEevaluated 8 times by 2 tests
Evaluated by:
  • tst_QNetworkProxyFactory
  • tst_QNetworkSession
8-78
253 d = engine->createSessionBackend();-
254 d->q = this;-
255 d->publicConfig = connectionConfig;-
256 d->syncStateWithInterface();-
257 connect(d, SIGNAL(quitPendingWaitsForOpened()), this, SIGNAL(opened()));-
258 connect(d, SIGNAL(error(QNetworkSession::SessionError)),-
259 this, SIGNAL(error(QNetworkSession::SessionError)));-
260 connect(d, SIGNAL(stateChanged(QNetworkSession::State)),-
261 this, SIGNAL(stateChanged(QNetworkSession::State)));-
262 connect(d, SIGNAL(closed()), this, SIGNAL(closed()));-
263 connect(d, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool)),-
264 this, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool)));-
265 connect(d, SIGNAL(newConfigurationActivated()),-
266 this, SIGNAL(newConfigurationActivated()));-
267 connect(d, SIGNAL(usagePoliciesChanged(QNetworkSession::UsagePolicies)),-
268 this, SIGNAL(usagePoliciesChanged(QNetworkSession::UsagePolicies)));-
269 break;
executed 78 times by 15 tests: break;
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QHostInfo
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QTcpServer
  • tst_QUdpSocket
  • tst_QXmlInputSource
  • tst_Spdy
78
270 }-
271 }
executed 8 times by 2 tests: end of block
Executed by:
  • tst_QNetworkProxyFactory
  • tst_QNetworkSession
8
272 }
executed 78 times by 15 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QHostInfo
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QTcpServer
  • tst_QUdpSocket
  • tst_QXmlInputSource
  • tst_Spdy
78
273-
274 qRegisterMetaType<QNetworkSession::State>();-
275 qRegisterMetaType<QNetworkSession::SessionError>();-
276 qRegisterMetaType<QNetworkSession::UsagePolicies>();-
277}
executed 80 times by 15 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QHostInfo
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QTcpServer
  • tst_QUdpSocket
  • tst_QXmlInputSource
  • tst_Spdy
80
278-
279/*!-
280 Frees the resources associated with the QNetworkSession object.-
281*/-
282QNetworkSession::~QNetworkSession()-
283{-
284 delete d;-
285}
executed 70 times by 12 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkSession
  • tst_Spdy
  • tst_networkselftest - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qhostinfo - unknown status
  • tst_qtcpserver - unknown status
  • tst_qudpsocket - unknown status
70
286-
287/*!-
288 Creates an open session which increases the session counter on the underlying network interface.-
289 The system will not terminate a network interface until the session reference counter reaches zero.-
290 Therefore an open session allows an application to register its use of the interface.-
291-
292 As a result of calling open() the interface will be started if it is not connected/up yet.-
293 Some platforms may not provide support for out-of-process sessions. On such platforms the session-
294 counter ignores any sessions held by another process. The platform capabilities can be-
295 detected via QNetworkConfigurationManager::capabilities().-
296-
297 Note that this call is asynchronous. Depending on the outcome of this call the results can be enquired-
298 by connecting to the stateChanged(), opened() or error() signals.-
299-
300 It is not a requirement to open a session in order to monitor the underlying network interface.-
301-
302 \sa close(), stop(), isOpen()-
303*/-
304void QNetworkSession::open()-
305{-
306 if (d)
dDescription
TRUEevaluated 70 times by 11 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QHostInfo
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QTcpServer
  • tst_QUdpSocket
  • tst_Spdy
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkSession
1-70
307 d->open();
executed 70 times by 11 tests: d->open();
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QHostInfo
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QTcpServer
  • tst_QUdpSocket
  • tst_Spdy
70
308 else-
309 emit error(InvalidConfigurationError);
executed 1 time by 1 test: error(InvalidConfigurationError);
Executed by:
  • tst_QNetworkSession
1
310}-
311-
312/*!-
313 Waits until the session has been opened, up to \a msecs milliseconds. If the session has been opened, this-
314 function returns \c true; otherwise it returns \c false. In the case where it returns \c false, you can call error()-
315 to determine the cause of the error.-
316-
317 The following example waits up to one second for the session to be opened:-
318-
319 \code-
320 session->open();-
321 if (session->waitForOpened(1000))-
322 qDebug("Open!");-
323 \endcode-
324-
325 If \a msecs is -1, this function will not time out.-
326-
327 \sa open(), error()-
328*/-
329bool QNetworkSession::waitForOpened(int msecs)-
330{-
331 if (!d)
!dDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkSession
FALSEevaluated 11 times by 9 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QHostInfo
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QTcpServer
  • tst_QUdpSocket
1-11
332 return false;
executed 1 time by 1 test: return false;
Executed by:
  • tst_QNetworkSession
1
333-
334 if (d->isOpen)
d->isOpenDescription
TRUEevaluated 11 times by 9 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QHostInfo
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QTcpServer
  • tst_QUdpSocket
FALSEnever evaluated
0-11
335 return true;
executed 11 times by 9 tests: return true;
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QHostInfo
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QTcpServer
  • tst_QUdpSocket
11
336-
337 if (!(d->state == Connecting || d->state == Connected)) {
d->state == ConnectingDescription
TRUEnever evaluated
FALSEnever evaluated
d->state == ConnectedDescription
TRUEnever evaluated
FALSEnever evaluated
0
338 return false;
never executed: return false;
0
339 }-
340-
341 QEventLoop loop;-
342 QObject::connect(d, SIGNAL(quitPendingWaitsForOpened()), &loop, SLOT(quit()));-
343 QObject::connect(this, SIGNAL(error(QNetworkSession::SessionError)), &loop, SLOT(quit()));-
344-
345 //final call-
346 if (msecs >= 0)
msecs >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
347 QTimer::singleShot(msecs, &loop, SLOT(quit()));
never executed: QTimer::singleShot(msecs, &loop, qFlagLocation("1""quit()" "\0" __FILE__ ":" "347"));
0
348-
349 // enter the event loop and wait for opened/error/timeout-
350 loop.exec(QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents);-
351-
352 return d->isOpen;
never executed: return d->isOpen;
0
353}-
354-
355/*!-
356 Decreases the session counter on the associated network configuration. If the session counter reaches zero-
357 the active network interface is shut down. This also means that state() will only change from \l Connected to-
358 \l Disconnected if the current session was the last open session.-
359-
360 If the platform does not support out-of-process sessions calling this function does not stop the-
361 interface. In this case \l{stop()} has to be used to force a shut down.-
362 The platform capabilities can be detected via QNetworkConfigurationManager::capabilities().-
363-
364 Note that this call is asynchronous. Depending on the outcome of this call the results can be enquired-
365 by connecting to the stateChanged(), opened() or error() signals.-
366-
367 \sa open(), stop(), isOpen()-
368*/-
369void QNetworkSession::close()-
370{-
371 if (d)
dDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEnever evaluated
0-4
372 d->close();
executed 4 times by 1 test: d->close();
Executed by:
  • tst_QNetworkReply
4
373}
executed 4 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
4
374-
375/*!-
376 Invalidates all open sessions against the network interface and therefore stops the-
377 underlying network interface. This function always changes the session's state() flag to-
378 \l Disconnected.-
379-
380 \sa open(), close()-
381*/-
382void QNetworkSession::stop()-
383{-
384 if (d)
dDescription
TRUEnever evaluated
FALSEnever evaluated
0
385 d->stop();
never executed: d->stop();
0
386}
never executed: end of block
0
387-
388/*!-
389 Returns the QNetworkConfiguration that this network session object is based on.-
390-
391 \sa QNetworkConfiguration-
392*/-
393QNetworkConfiguration QNetworkSession::configuration() const-
394{-
395 return d ? d->publicConfig : QNetworkConfiguration();
executed 516 times by 4 tests: return d ? d->publicConfig : QNetworkConfiguration();
Executed by:
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
dDescription
TRUEevaluated 515 times by 4 tests
Evaluated by:
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkSession
1-516
396}-
397-
398#ifndef QT_NO_NETWORKINTERFACE-
399/*!-
400 Returns the network interface that is used by this session.-
401-
402 This function only returns a valid QNetworkInterface when this session is \l Connected.-
403-
404 The returned interface may change as a result of a roaming process.-
405-
406 \sa state()-
407*/-
408QNetworkInterface QNetworkSession::interface() const-
409{-
410 return d ? d->currentInterface() : QNetworkInterface();
executed 4 times by 1 test: return d ? d->currentInterface() : QNetworkInterface();
Executed by:
  • tst_QNetworkSession
dDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QNetworkSession
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkSession
1-4
411}-
412#endif-
413-
414/*!-
415 Returns \c true if this session is open. If the number of all open sessions is greater than-
416 zero the underlying network interface will remain connected/up.-
417-
418 The session can be controlled via open() and close().-
419*/-
420bool QNetworkSession::isOpen() const-
421{-
422 return d ? d->isOpen : false;
executed 1297 times by 10 tests: return d ? d->isOpen : false;
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QHostInfo
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QUdpSocket
  • tst_Spdy
dDescription
TRUEevaluated 1296 times by 10 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QHostInfo
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QUdpSocket
  • tst_Spdy
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkSession
1-1297
423}-
424-
425/*!-
426 Returns the state of the session.-
427-
428 If the session is based on a single access point configuration the state of the-
429 session is the same as the state of the associated network interface. Therefore-
430 a network session object can be used to monitor network interfaces.-
431-
432 A \l QNetworkConfiguration::ServiceNetwork based session summarizes the state of all its children-
433 and therefore returns the \l Connected state if at least one of the service network's-
434 \l {QNetworkConfiguration::children()}{children()} configurations is active.-
435-
436 Note that it is not required to hold an open session in order to obtain the network interface state.-
437 A connected but closed session may be used to monitor network interfaces whereas an open and connected-
438 session object may prevent the network interface from being shut down.-
439-
440 \sa error(), stateChanged()-
441*/-
442QNetworkSession::State QNetworkSession::state() const-
443{-
444 return d ? d->state : QNetworkSession::Invalid;
executed 2087 times by 10 tests: return d ? d->state : QNetworkSession::Invalid;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QXmlInputSource
  • tst_Spdy
dDescription
TRUEevaluated 2083 times by 10 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QXmlInputSource
  • tst_Spdy
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QNetworkSession
4-2087
445}-
446-
447/*!-
448 Returns the type of error that last occurred.-
449-
450 \sa state(), errorString()-
451*/-
452QNetworkSession::SessionError QNetworkSession::error() const-
453{-
454 return d ? d->error() : InvalidConfigurationError;
executed 2 times by 1 test: return d ? d->error() : InvalidConfigurationError;
Executed by:
  • tst_QNetworkSession
dDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QNetworkSession
0-2
455}-
456-
457/*!-
458 Returns a human-readable description of the last device error that-
459 occurred.-
460-
461 \sa error()-
462*/-
463QString QNetworkSession::errorString() const-
464{-
465 return d ? d->errorString() : tr("Invalid configuration.");
never executed: return d ? d->errorString() : tr("Invalid configuration.");
dDescription
TRUEnever evaluated
FALSEnever evaluated
0
466}-
467-
468/*!-
469 Returns the value for property \a key.-
470-
471 A network session can have properties attached which may describe the session in more details.-
472 This function can be used to gain access to those properties.-
473-
474 The following property keys are guaranteed to be specified on all platforms:-
475-
476 \table 80%-
477 \header-
478 \li Key \li Description-
479 \row-
480 \li ActiveConfiguration-
481 \li If the session \l isOpen() this property returns the identifier of the-
482 QNetworkConfiguration that is used by this session; otherwise an empty string.-
483-
484 The main purpose of this key is to determine which Internet access point is used-
485 if the session is based on a \l{QNetworkConfiguration::ServiceNetwork}{ServiceNetwork}.-
486 The following code snippet highlights the difference:-
487 \code-
488 QNetworkConfigurationManager mgr;-
489 QNetworkConfiguration ap = mgr.defaultConfiguration();-
490 QNetworkSession *session = new QNetworkSession(ap);-
491 ... //code activates session-
492-
493 QString ident = session->sessionProperty("ActiveConfiguration").toString();-
494 if ( ap.type() == QNetworkConfiguration::ServiceNetwork ) {-
495 Q_ASSERT( ap.identifier() != ident );-
496 Q_ASSERT( ap.children().contains( mgr.configurationFromIdentifier(ident) ) );-
497 } else if ( ap.type() == QNetworkConfiguration::InternetAccessPoint ) {-
498 Q_ASSERT( ap.identifier() == ident );-
499 }-
500 \endcode-
501 \row-
502 \li UserChoiceConfiguration-
503 \li If the session \l isOpen() and is bound to a QNetworkConfiguration of type-
504 UserChoice, this property returns the identifier of the QNetworkConfiguration that the-
505 configuration resolved to when \l open() was called; otherwise an empty string.-
506-
507 The purpose of this key is to determine the real QNetworkConfiguration that the-
508 session is using. This key is different from \e ActiveConfiguration in that-
509 this key may return an identifier for either a-
510 \l {QNetworkConfiguration::ServiceNetwork}{service network} or a-
511 \l {QNetworkConfiguration::InternetAccessPoint}{Internet access points} configurations,-
512 whereas \e ActiveConfiguration always returns identifiers to-
513 \l {QNetworkConfiguration::InternetAccessPoint}{Internet access points} configurations.-
514 \row-
515 \li ConnectInBackground-
516 \li Setting this property to \e true before calling \l open() implies that the connection attempt-
517 is made but if no connection can be established, the user is not connsulted and asked to select-
518 a suitable connection. This property is not set by default and support for it depends on the platform.-
519-
520 \row-
521 \li AutoCloseSessionTimeout-
522 \li If the session requires polling to keep its state up to date, this property holds-
523 the timeout in milliseconds before the session will automatically close. If the-
524 value of this property is -1 the session will not automatically close. This property-
525 is set to -1 by default.-
526-
527 The purpose of this property is to minimize resource use on platforms that use-
528 polling to update the state of the session. Applications can set the value of this-
529 property to the desired timeout before the session is closed. In response to the-
530 closed() signal the network session should be deleted to ensure that all polling is-
531 stopped. The session can then be recreated once it is required again. This property-
532 has no effect for sessions that do not require polling.-
533 \endtable-
534*/-
535QVariant QNetworkSession::sessionProperty(const QString &key) const-
536{-
537 if (!d || !d->publicConfig.isValid())
!dDescription
TRUEnever evaluated
FALSEevaluated 127 times by 3 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
  • tst_QNetworkSession
!d->publicConfig.isValid()Description
TRUEnever evaluated
FALSEevaluated 127 times by 3 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
  • tst_QNetworkSession
0-127
538 return QVariant();
never executed: return QVariant();
0
539-
540 if (key == QLatin1String("ActiveConfiguration"))
key == QLatin1...onfiguration")Description
TRUEevaluated 116 times by 2 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
FALSEevaluated 11 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QNetworkSession
11-116
541 return d->isOpen ? d->activeConfig.identifier() : QString();
executed 116 times by 2 tests: return d->isOpen ? d->activeConfig.identifier() : QString();
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
d->isOpenDescription
TRUEevaluated 116 times by 2 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
FALSEnever evaluated
0-116
542-
543 if (key == QLatin1String("UserChoiceConfiguration")) {
key == QLatin1...onfiguration")Description
TRUEnever evaluated
FALSEevaluated 11 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QNetworkSession
0-11
544 if (!d->isOpen || d->publicConfig.type() != QNetworkConfiguration::UserChoice)
!d->isOpenDescription
TRUEnever evaluated
FALSEnever evaluated
d->publicConfi...on::UserChoiceDescription
TRUEnever evaluated
FALSEnever evaluated
0
545 return QString();
never executed: return QString();
0
546-
547 if (d->serviceConfig.isValid())
d->serviceConfig.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
548 return d->serviceConfig.identifier();
never executed: return d->serviceConfig.identifier();
0
549 else-
550 return d->activeConfig.identifier();
never executed: return d->activeConfig.identifier();
0
551 }-
552-
553 return d->sessionProperty(key);
executed 11 times by 2 tests: return d->sessionProperty(key);
Executed by:
  • tst_QNetworkReply
  • tst_QNetworkSession
11
554}-
555-
556/*!-
557 Sets the property \a value on the session. The property is identified using-
558 \a key. Removing an already set property can be achieved by passing an-
559 invalid QVariant.-
560-
561 Note that the \e UserChoiceConfiguration and \e ActiveConfiguration-
562 properties are read only and cannot be changed using this method.-
563*/-
564void QNetworkSession::setSessionProperty(const QString &key, const QVariant &value)-
565{-
566 if (!d)
!dDescription
TRUEnever evaluated
FALSEevaluated 61 times by 6 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_Spdy
0-61
567 return;
never executed: return;
0
568-
569 if (key == QLatin1String("ActiveConfiguration") ||
key == QLatin1...onfiguration")Description
TRUEnever evaluated
FALSEevaluated 61 times by 6 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_Spdy
0-61
570 key == QLatin1String("UserChoiceConfiguration")) {
key == QLatin1...onfiguration")Description
TRUEnever evaluated
FALSEevaluated 61 times by 6 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_Spdy
0-61
571 return;
never executed: return;
0
572 }-
573-
574 d->setSessionProperty(key, value);-
575}
executed 61 times by 6 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_Spdy
61
576-
577/*!-
578 Instructs the session to roam to the new access point. The old access point remains active-
579 until the application calls accept().-
580-
581 The newConfigurationActivated() signal is emitted once roaming has been completed.-
582-
583 \sa accept()-
584*/-
585void QNetworkSession::migrate()-
586{-
587 if (d)
dDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkSession
FALSEnever evaluated
0-1
588 d->migrate();
executed 1 time by 1 test: d->migrate();
Executed by:
  • tst_QNetworkSession
1
589}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QNetworkSession
1
590-
591/*!-
592 This function indicates that the application does not wish to roam the session.-
593-
594 \sa migrate()-
595*/-
596void QNetworkSession::ignore()-
597{-
598 if (d)
dDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkSession
FALSEnever evaluated
0-1
599 d->ignore();
executed 1 time by 1 test: d->ignore();
Executed by:
  • tst_QNetworkSession
1
600}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QNetworkSession
1
601-
602/*!-
603 Instructs the session to permanently accept the new access point. Once this function-
604 has been called the session may not return to the old access point.-
605-
606 The old access point may be closed in the process if there are no other network sessions for it.-
607 Therefore any open socket that still uses the old access point-
608 may become unusable and should be closed before completing the migration.-
609*/-
610void QNetworkSession::accept()-
611{-
612 if (d)
dDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkSession
FALSEnever evaluated
0-1
613 d->accept();
executed 1 time by 1 test: d->accept();
Executed by:
  • tst_QNetworkSession
1
614}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QNetworkSession
1
615-
616/*!-
617 The new access point is not suitable for the application. By calling this function the-
618 session returns to the previous access point/configuration. This action may invalidate-
619 any socket that has been created via the not desired access point.-
620-
621 \sa accept()-
622*/-
623void QNetworkSession::reject()-
624{-
625 if (d)
dDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkSession
FALSEnever evaluated
0-1
626 d->reject();
executed 1 time by 1 test: d->reject();
Executed by:
  • tst_QNetworkSession
1
627}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QNetworkSession
1
628-
629-
630/*!-
631 Returns the amount of data sent in bytes; otherwise 0.-
632-
633 This field value includes the usage across all open network-
634 sessions which use the same network interface.-
635-
636 If the session is based on a service network configuration the number of-
637 sent bytes across all active member configurations are returned.-
638-
639 This function may not always be supported on all platforms and returns 0.-
640 The platform capability can be detected via QNetworkConfigurationManager::DataStatistics.-
641-
642 \note On some platforms this function may run the main event loop.-
643*/-
644quint64 QNetworkSession::bytesWritten() const-
645{-
646 return d ? d->bytesWritten() : Q_UINT64_C(0);
never executed: return d ? d->bytesWritten() : static_cast<unsigned long long>(0ULL);
dDescription
TRUEnever evaluated
FALSEnever evaluated
0
647}-
648-
649/*!-
650 Returns the amount of data received in bytes; otherwise 0.-
651-
652 This field value includes the usage across all open network-
653 sessions which use the same network interface.-
654-
655 If the session is based on a service network configuration the number of-
656 sent bytes across all active member configurations are returned.-
657-
658 This function may not always be supported on all platforms and returns 0.-
659 The platform capability can be detected via QNetworkConfigurationManager::DataStatistics.-
660-
661 \note On some platforms this function may run the main event loop.-
662*/-
663quint64 QNetworkSession::bytesReceived() const-
664{-
665 return d ? d->bytesReceived() : Q_UINT64_C(0);
never executed: return d ? d->bytesReceived() : static_cast<unsigned long long>(0ULL);
dDescription
TRUEnever evaluated
FALSEnever evaluated
0
666}-
667-
668/*!-
669 Returns the number of seconds that the session has been active.-
670*/-
671quint64 QNetworkSession::activeTime() const-
672{-
673 return d ? d->activeTime() : Q_UINT64_C(0);
never executed: return d ? d->activeTime() : static_cast<unsigned long long>(0ULL);
dDescription
TRUEnever evaluated
FALSEnever evaluated
0
674}-
675-
676/*!-
677 Returns the network usage policies currently in force by the system.-
678*/-
679QNetworkSession::UsagePolicies QNetworkSession::usagePolicies() const-
680{-
681 return d ? d->usagePolicies() : QNetworkSession::NoPolicy;
executed 38 times by 2 tests: return d ? d->usagePolicies() : QNetworkSession::NoPolicy;
Executed by:
  • tst_QNetworkReply
  • tst_QNetworkSession
dDescription
TRUEevaluated 38 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QNetworkSession
FALSEnever evaluated
0-38
682}-
683-
684/*!-
685 \internal-
686 Change usage policies for unit testing.-
687 In normal use, the policies are published by the bearer plugin-
688*/-
689void QNetworkSessionPrivate::setUsagePolicies(QNetworkSession &session, QNetworkSession::UsagePolicies policies)-
690{-
691 if (!session.d)
!session.dDescription
TRUEnever evaluated
FALSEevaluated 48 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QNetworkSession
0-48
692 return;
never executed: return;
0
693 session.d->setUsagePolicies(policies);-
694}
executed 48 times by 2 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_QNetworkSession
48
695-
696/*!-
697 \internal-
698-
699 This function is required to detect whether the client wants to control-
700 the roaming process. If he connects to preferredConfigurationChanged() signal-
701 he intends to influence it. Otherwise QNetworkSession always roams-
702 without registering this session as a stakeholder in the roaming process.-
703-
704 For more details check the Forced vs ALR roaming section in the QNetworkSession-
705 class description.-
706*/-
707void QNetworkSession::connectNotify(const QMetaMethod &signal)-
708{-
709 QObject::connectNotify(signal);-
710-
711 if (!d)
!dDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkSession
FALSEevaluated 2284 times by 10 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QXmlInputSource
  • tst_Spdy
1-2284
712 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QNetworkSession
1
713-
714 //check for preferredConfigurationChanged() signal connect notification-
715 //This is not required on all platforms-
716 static const QMetaMethod preferredConfigurationChangedSignal =-
717 QMetaMethod::fromSignal(&QNetworkSession::preferredConfigurationChanged);-
718 if (signal == preferredConfigurationChangedSignal)
signal == pref...nChangedSignalDescription
TRUEnever evaluated
FALSEevaluated 2284 times by 10 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QXmlInputSource
  • tst_Spdy
0-2284
719 d->setALREnabled(true);
never executed: d->setALREnabled(true);
0
720}
executed 2284 times by 10 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QXmlInputSource
  • tst_Spdy
2284
721-
722/*!-
723 \internal-
724-
725 This function is called when the client disconnects from the-
726 preferredConfigurationChanged() signal.-
727-
728 \sa connectNotify()-
729*/-
730void QNetworkSession::disconnectNotify(const QMetaMethod &signal)-
731{-
732 QObject::disconnectNotify(signal);-
733-
734 if (!d)
!dDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkSession
FALSEevaluated 2227 times by 11 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_spdy - unknown status
1-2227
735 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QNetworkSession
1
736-
737 //check for preferredConfigurationChanged() signal disconnect notification-
738 //This is not required on all platforms-
739 static const QMetaMethod preferredConfigurationChangedSignal =-
740 QMetaMethod::fromSignal(&QNetworkSession::preferredConfigurationChanged);-
741 if (signal == preferredConfigurationChangedSignal)
signal == pref...nChangedSignalDescription
TRUEnever evaluated
FALSEevaluated 2227 times by 11 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_spdy - unknown status
0-2227
742 d->setALREnabled(false);
never executed: d->setALREnabled(false);
0
743}
executed 2227 times by 11 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QXmlInputSource
  • tst_Spdy
  • tst_spdy - unknown status
2227
744-
745#include "moc_qnetworksession.cpp"-
746-
747QT_END_NAMESPACE-
748-
749#endif // QT_NO_BEARERMANAGEMENT-
Source codeSwitch to Preprocessed file

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