diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-03-25 22:09:36 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-03-25 22:09:36 (GMT) |
commit | 11b9190a182c5f3c1055c100145b02a3975509ed (patch) | |
tree | 2c664ad92363204c320e23f9d1e6ca29505eaf2e /src/network | |
parent | 03686225036ebfc5cf78e3fcc66f5810a140c7d2 (diff) | |
parent | 3671dbf34940e166b747b6f8f3f5758fd486073c (diff) | |
download | Qt-11b9190a182c5f3c1055c100145b02a3975509ed.zip Qt-11b9190a182c5f3c1055c100145b02a3975509ed.tar.gz Qt-11b9190a182c5f3c1055c100145b02a3975509ed.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt into 4.7
Conflicts:
src/declarative/graphicsitems/qdeclarativeitem.cpp
Diffstat (limited to 'src/network')
19 files changed, 184 insertions, 89 deletions
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 1940dd1..197d89e 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -173,40 +173,58 @@ static void ensureInitialized() */ /*! - \property QNetworkAccessManager::networkAccess - \brief states whether network access is enabled or disabled through this network access - manager. + \enum QNetworkAccessManager::NetworkAccessibility + + Indicates whether the network is accessible via this network access manager. + + \value UnknownAccessibility The network accessibility cannot be determined. + \value NotAccessible The network is not currently accessible, either because there + is currently no network coverage or network access has been + explicitly disabled by a call to setNetworkAccessible(). + \value Accessible The network is accessible. + + \sa networkAccessible +*/ + +/*! + \property QNetworkAccessManager::networkAccessible + \brief whether the network is currently accessible via this network access manager. \since 4.7 - Network access is enabled by default. + If the network is \l {NotAccessible}{not accessible} the network access manager will not + process any new network requests, all such requests will fail with an error. Requests with + URLs with the file:// scheme will still be processed. + + By default the value of this property reflects the physical state of the device. Applications + may override it to disable all network requests via this network access manager by calling + + \snippet doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp 4 + + Network requests can be reenabled again by calling - When network access is disabled the network access manager will not process any new network - requests, all such requests will fail with an error. Requests with URLs with the file:// scheme - will still be processed. + \snippet doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp 5 - This property can be used to enable and disable network access for all clients of a single - network access manager instance. + \note Calling setNetworkAccessible() does not change the network state. */ /*! - \fn void QNetworkAccessManager::networkAccessChanged(bool enabled) + \fn void QNetworkAccessManager::networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessible) - This signal is emitted when the value of the \l networkAccess property changes. If \a enabled - is true new requests that access the network will be processed; otherwise new network requests - that require network access will fail with an error. + This signal is emitted when the value of the \l networkAccessible property changes. + \a accessible is the new network accessibility. */ /*! - \fn void QNetworkAccessManager::networkSessionOnline() + \fn void QNetworkAccessManager::networkSessionConnected() \since 4.7 \internal - This signal is emitted when the status of the network session changes into a usable state. - It is used to signal QNetworkReply's to start or migrate their network operation once the - network session has been opened / roamed. + This signal is emitted when the status of the network session changes into a usable (Connected) + state. It is used to signal to QNetworkReplys to start or migrate their network operation once + the network session has been opened or finished roaming. */ /*! @@ -792,30 +810,42 @@ QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const /*! \since 4.7 - Enables network access via this QNetworkAccessManager if \a enabled is true; otherwise disables - access. + Overrides the reported network accessibility. If \a accessible is NotAccessible the reported + network accessiblity will always be NotAccessible. Otherwise the reported network + accessibility will reflect the actual device state. */ -void QNetworkAccessManager::setNetworkAccessEnabled(bool enabled) +void QNetworkAccessManager::setNetworkAccessible(QNetworkAccessManager::NetworkAccessibility accessible) { Q_D(QNetworkAccessManager); - if (d->networkAccessEnabled != enabled) { - d->networkAccessEnabled = enabled; - emit networkAccessChanged(enabled); + if (d->networkAccessible != accessible) { + NetworkAccessibility previous = networkAccessible(); + d->networkAccessible = accessible; + NetworkAccessibility current = networkAccessible(); + if (previous != current) + emit networkAccessibleChanged(current); } } /*! \since 4.7 - Returns true if network access via this QNetworkAccessManager is enabled; otherwise returns - false. + Returns the current network accessibility. */ -bool QNetworkAccessManager::networkAccessEnabled() const +QNetworkAccessManager::NetworkAccessibility QNetworkAccessManager::networkAccessible() const { Q_D(const QNetworkAccessManager); - return d->networkAccessEnabled; + if (d->networkSession) { + // d->online holds online/offline state of this network session. + if (d->online) + return d->networkAccessible; + else + return NotAccessible; + } else { + // Network accessibility is either disabled or unknown. + return (d->networkAccessible == NotAccessible) ? NotAccessible : UnknownAccessibility; + } } /*! @@ -875,20 +905,22 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera // Return a disabled network reply if network access is disabled. // Except if the scheme is empty or file://. - if (!d->networkAccessEnabled && !(req.url().scheme() == QLatin1String("file") || + if (!d->networkAccessible && !(req.url().scheme() == QLatin1String("file") || req.url().scheme().isEmpty())) { return new QDisabledNetworkReply(this, req, op); } -#ifdef QT_QNAM_DEFAULT_NETWORK_SESSION if (!d->networkSession && (d->initializeSession || !d->networkConfiguration.isEmpty())) { QNetworkConfigurationManager manager; - if (d->networkConfiguration.isEmpty()) - d->createSession(manager.defaultConfiguration()); - else + if (!d->networkConfiguration.isEmpty()) { d->createSession(manager.configurationFromIdentifier(d->networkConfiguration)); + } else { + if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) + d->createSession(manager.defaultConfiguration()); + else + d->initializeSession = false; + } } -#endif if (d->networkSession) d->networkSession->setSessionProperty(QLatin1String("AutoCloseSessionTimeout"), -1); @@ -909,8 +941,10 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera // first step: create the reply QUrl url = request.url(); QNetworkReplyImpl *reply = new QNetworkReplyImpl(this); - if (req.url().scheme() != QLatin1String("file") && !req.url().scheme().isEmpty()) - connect(this, SIGNAL(networkSessionOnline()), reply, SLOT(_q_networkSessionOnline())); + if (req.url().scheme() != QLatin1String("file") && !req.url().scheme().isEmpty()) { + connect(this, SIGNAL(networkSessionConnected()), + reply, SLOT(_q_networkSessionConnected())); + } QNetworkReplyImplPrivate *priv = reply->d_func(); priv->manager = this; @@ -1208,28 +1242,37 @@ void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &co { Q_Q(QNetworkAccessManager); -#ifdef QT_QNAM_DEFAULT_NETWORK_SESSION initializeSession = false; -#endif if (networkSession) delete networkSession; if (!config.isValid()) { networkSession = 0; + online = false; + + if (networkAccessible == QNetworkAccessManager::NotAccessible) + emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible); + else + emit q->networkAccessibleChanged(QNetworkAccessManager::UnknownAccessibility); + return; } networkSession = new QNetworkSession(config, q); - QObject::connect(networkSession, SIGNAL(opened()), q, SIGNAL(networkSessionOnline())); + QObject::connect(networkSession, SIGNAL(opened()), q, SIGNAL(networkSessionConnected())); QObject::connect(networkSession, SIGNAL(closed()), q, SLOT(_q_networkSessionClosed())); + QObject::connect(networkSession, SIGNAL(stateChanged(QNetworkSession::State)), + q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State))); QObject::connect(networkSession, SIGNAL(newConfigurationActivated()), q, SLOT(_q_networkSessionNewConfigurationActivated())); QObject::connect(networkSession, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool)), q, SLOT(_q_networkSessionPreferredConfigurationChanged(QNetworkConfiguration,bool))); + + _q_networkSessionStateChanged(networkSession->state()); } void QNetworkAccessManagerPrivate::_q_networkSessionClosed() @@ -1249,7 +1292,7 @@ void QNetworkAccessManagerPrivate::_q_networkSessionNewConfigurationActivated() if (networkSession) { networkSession->accept(); - emit q->networkSessionOnline(); + emit q->networkSessionConnected(); } } @@ -1259,6 +1302,23 @@ void QNetworkAccessManagerPrivate::_q_networkSessionPreferredConfigurationChange networkSession->migrate(); } +void QNetworkAccessManagerPrivate::_q_networkSessionStateChanged(QNetworkSession::State state) +{ + Q_Q(QNetworkAccessManager); + + if (online) { + if (state != QNetworkSession::Connected && state != QNetworkSession::Roaming) { + online = false; + emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible); + } + } else { + if (state == QNetworkSession::Connected || state == QNetworkSession::Roaming) { + online = true; + emit q->networkAccessibleChanged(networkAccessible); + } + } +} + QT_END_NAMESPACE #include "moc_qnetworkaccessmanager.cpp" diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h index 694a54f..c57c9c6 100644 --- a/src/network/access/qnetworkaccessmanager.h +++ b/src/network/access/qnetworkaccessmanager.h @@ -70,7 +70,7 @@ class Q_NETWORK_EXPORT QNetworkAccessManager: public QObject { Q_OBJECT - Q_PROPERTY(bool networkAccess READ networkAccessEnabled WRITE setNetworkAccessEnabled NOTIFY networkAccessChanged) + Q_PROPERTY(NetworkAccessibility networkAccessible READ networkAccessible WRITE setNetworkAccessible NOTIFY networkAccessibleChanged) public: enum Operation { @@ -84,6 +84,12 @@ public: UnknownOperation = 0 }; + enum NetworkAccessibility { + UnknownAccessibility = -1, + NotAccessible = 0, + Accessible = 1 + }; + explicit QNetworkAccessManager(QObject *parent = 0); ~QNetworkAccessManager(); @@ -113,8 +119,8 @@ public: QNetworkConfiguration configuration() const; QNetworkConfiguration activeConfiguration() const; - void setNetworkAccessEnabled(bool enabled); - bool networkAccessEnabled() const; + void setNetworkAccessible(NetworkAccessibility accessible); + NetworkAccessibility networkAccessible() const; Q_SIGNALS: #ifndef QT_NO_NETWORKPROXY @@ -126,9 +132,9 @@ Q_SIGNALS: void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors); #endif - void networkSessionOnline(); + void networkSessionConnected(); - void networkAccessChanged(bool enabled); + void networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessible); protected: virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &request, @@ -142,6 +148,7 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_networkSessionClosed()) Q_PRIVATE_SLOT(d_func(), void _q_networkSessionNewConfigurationActivated()) Q_PRIVATE_SLOT(d_func(), void _q_networkSessionPreferredConfigurationChanged(QNetworkConfiguration,bool)) + Q_PRIVATE_SLOT(d_func(), void _q_networkSessionStateChanged(QNetworkSession::State)) }; QT_END_NAMESPACE diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h index 4a2a840..1785685 100644 --- a/src/network/access/qnetworkaccessmanager_p.h +++ b/src/network/access/qnetworkaccessmanager_p.h @@ -58,6 +58,7 @@ #include "qnetworkaccessbackend_p.h" #include "private/qobject_p.h" #include "QtNetwork/qnetworkproxy.h" +#include "QtNetwork/qnetworksession.h" QT_BEGIN_NAMESPACE @@ -65,7 +66,6 @@ class QAuthenticator; class QAbstractNetworkCache; class QNetworkAuthenticationCredential; class QNetworkCookieJar; -class QNetworkSession; class QNetworkAccessManagerPrivate: public QObjectPrivate { @@ -76,10 +76,9 @@ public: proxyFactory(0), #endif networkSession(0), - networkAccessEnabled(true), -#ifdef QT_QNAM_DEFAULT_NETWORK_SESSION + networkAccessible(QNetworkAccessManager::Accessible), + online(false), initializeSession(true), -#endif cookieJarCreated(false) { } ~QNetworkAccessManagerPrivate(); @@ -111,6 +110,7 @@ public: void _q_networkSessionNewConfigurationActivated(); void _q_networkSessionPreferredConfigurationChanged(const QNetworkConfiguration &config, bool isSeamless); + void _q_networkSessionStateChanged(QNetworkSession::State state); // this is the cache for storing downloaded files QAbstractNetworkCache *networkCache; @@ -125,10 +125,9 @@ public: QNetworkSession *networkSession; QString networkConfiguration; - bool networkAccessEnabled; -#ifdef QT_QNAM_DEFAULT_NETWORK_SESSION + QNetworkAccessManager::NetworkAccessibility networkAccessible; + bool online; bool initializeSession; -#endif bool cookieJarCreated; diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 8505a41..edd6889 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -232,10 +232,20 @@ void QNetworkReplyImplPrivate::_q_bufferOutgoingData() } } -void QNetworkReplyImplPrivate::_q_networkSessionOnline() +void QNetworkReplyImplPrivate::_q_networkSessionConnected() { Q_Q(QNetworkReplyImpl); + if (manager.isNull()) + return; + + QNetworkSession *session = manager->d_func()->networkSession; + if (!session) + return; + + if (session->state() != QNetworkSession::Connected) + return; + switch (state) { case QNetworkReplyImplPrivate::Buffering: case QNetworkReplyImplPrivate::Working: @@ -308,11 +318,15 @@ void QNetworkReplyImplPrivate::setup(QNetworkAccessManager::Operation op, const // for HTTP, we want to send out the request as fast as possible to the network, without // invoking methods in a QueuedConnection +#ifndef QT_NO_HTTP if (qobject_cast<QNetworkAccessHttpBackend *>(backend)) { _q_startOperation(); } else { QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); } +#else + QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); +#endif // QT_NO_HTTP } q->QIODevice::open(QIODevice::ReadOnly); @@ -862,11 +876,15 @@ bool QNetworkReplyImplPrivate::migrateBackend() backend->setResumeOffset(bytesDownloaded); } +#ifndef QT_NO_HTTP if (qobject_cast<QNetworkAccessHttpBackend *>(backend)) { _q_startOperation(); } else { QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); } +#else + QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); +#endif // QT_NO_HTTP return true; } diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h index 6045ef4..fcb3397 100644 --- a/src/network/access/qnetworkreplyimpl_p.h +++ b/src/network/access/qnetworkreplyimpl_p.h @@ -99,7 +99,7 @@ public: Q_PRIVATE_SLOT(d_func(), void _q_copyReadChannelFinished()) Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingData()) Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingDataFinished()) - Q_PRIVATE_SLOT(d_func(), void _q_networkSessionOnline()) + Q_PRIVATE_SLOT(d_func(), void _q_networkSessionConnected()) Q_PRIVATE_SLOT(d_func(), void _q_networkSessionFailed()) }; @@ -133,7 +133,7 @@ public: void _q_copyReadChannelFinished(); void _q_bufferOutgoingData(); void _q_bufferOutgoingDataFinished(); - void _q_networkSessionOnline(); + void _q_networkSessionConnected(); void _q_networkSessionFailed(); void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request, diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index e7595a4..1ba5dab 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -64,7 +64,7 @@ QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate() \since 4.7 \inmodule QtNetwork - \ingroup bearer + \ingroup network QNetworkConfigurationManager provides access to the network configurations known to the system and enables applications to detect the system capabilities (with regards to network sessions) at runtime. @@ -166,6 +166,8 @@ QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate() sockets. \value DataStatistics If this flag is set QNetworkSession can provide statistics about transmitted and received data. + \value NetworkSessionRequired If this flag is set the platform requires that a network + session is created before network operations can be performed. */ /*! diff --git a/src/network/bearer/qnetworkconfigmanager.h b/src/network/bearer/qnetworkconfigmanager.h index 73041fe..bb4d8a0 100644 --- a/src/network/bearer/qnetworkconfigmanager.h +++ b/src/network/bearer/qnetworkconfigmanager.h @@ -64,7 +64,8 @@ public: SystemSessionSupport = 0x00000004, ApplicationLevelRoaming = 0x00000008, ForcedRoaming = 0x00000010, - DataStatistics = 0x00000020 + DataStatistics = 0x00000020, + NetworkSessionRequired = 0x00000040 }; Q_DECLARE_FLAGS(Capabilities, Capability) diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 8ec8152..dba9d2c 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -57,6 +57,7 @@ #include "qnetworkconfiguration_p.h" #include <QtCore/qmutex.h> +#include <QtCore/qset.h> QT_BEGIN_NAMESPACE diff --git a/src/network/bearer/qnetworkconfiguration.cpp b/src/network/bearer/qnetworkconfiguration.cpp index 82669e0..4108fee 100644 --- a/src/network/bearer/qnetworkconfiguration.cpp +++ b/src/network/bearer/qnetworkconfiguration.cpp @@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE \since 4.7 \inmodule QtNetwork - \ingroup bearer + \ingroup network QNetworkConfiguration encapsulates a single access point or service network. In most cases a single access point configuration can be mapped to one network diff --git a/src/network/bearer/qnetworkconfiguration_p.h b/src/network/bearer/qnetworkconfiguration_p.h index 6908277..ccbe670 100644 --- a/src/network/bearer/qnetworkconfiguration_p.h +++ b/src/network/bearer/qnetworkconfiguration_p.h @@ -57,7 +57,6 @@ #include <QtCore/qshareddata.h> #include <QtCore/qmutex.h> -#include <QtNetwork/QNetworkInterface> QT_BEGIN_NAMESPACE @@ -72,7 +71,7 @@ public: { } - ~QNetworkConfigurationPrivate() + virtual ~QNetworkConfigurationPrivate() { //release pointers to member configurations serviceNetworkMembers.clear(); diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index cf9f4b2..1bba56f 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE \since 4.7 \inmodule QtNetwork - \ingroup bearer + \ingroup network A QNetworkSession enables control over the system's network interfaces. The session's configuration parameter are determined via the QNetworkConfiguration object to which it is bound. Depending on the @@ -370,6 +370,7 @@ QNetworkConfiguration QNetworkSession::configuration() const return d ? d->publicConfig : QNetworkConfiguration(); } +#ifndef QT_NO_NETWORKINTERFACE /*! Returns the network interface that is used by this session. @@ -386,6 +387,7 @@ QNetworkInterface QNetworkSession::interface() const { return d ? d->currentInterface() : QNetworkInterface(); } +#endif /*! Returns true if this session is open. If the number of all open sessions is greater than diff --git a/src/network/bearer/qnetworksession.h b/src/network/bearer/qnetworksession.h index 18437f6..596f527 100644 --- a/src/network/bearer/qnetworksession.h +++ b/src/network/bearer/qnetworksession.h @@ -48,6 +48,10 @@ #include <QtCore/qvariant.h> #include <QtNetwork/qnetworkconfiguration.h> +#if defined(Q_OS_WIN) && defined(interface) +#undef interface +#endif + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -77,12 +81,14 @@ public: InvalidConfigurationError }; - QNetworkSession(const QNetworkConfiguration& connConfig, QObject* parent =0); + explicit QNetworkSession(const QNetworkConfiguration& connConfig, QObject* parent =0); virtual ~QNetworkSession(); bool isOpen() const; QNetworkConfiguration configuration() const; +#ifndef QT_NO_NETWORKINTERFACE QNetworkInterface interface() const; +#endif State state() const; SessionError error() const; diff --git a/src/network/bearer/qnetworksession_p.h b/src/network/bearer/qnetworksession_p.h index 76691b3..a341eaf 100644 --- a/src/network/bearer/qnetworksession_p.h +++ b/src/network/bearer/qnetworksession_p.h @@ -56,8 +56,6 @@ #include "qnetworksession.h" #include "qnetworkconfiguration_p.h" -#include <QNetworkInterface> - QT_BEGIN_NAMESPACE class Q_NETWORK_EXPORT QNetworkSessionPrivate : public QObject @@ -82,7 +80,9 @@ public: //notification hooks to discover future state changes. virtual void syncStateWithInterface() = 0; +#ifndef QT_NO_NETWORKINTERFACE virtual QNetworkInterface currentInterface() const = 0; +#endif virtual QVariant sessionProperty(const QString& key) const = 0; virtual void setSessionProperty(const QString& key, const QVariant& value) = 0; diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index 95721ee..21cd0fd 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -365,12 +365,12 @@ #include "private/qhostinfo_p.h" #include <qabstracteventdispatcher.h> -#include <qdatetime.h> #include <qhostaddress.h> #include <qhostinfo.h> #include <qmetaobject.h> #include <qpointer.h> #include <qtimer.h> +#include <qelapsedtimer.h> #ifndef QT_NO_OPENSSL #include <QtNetwork/qsslsocket.h> @@ -1738,7 +1738,7 @@ bool QAbstractSocket::waitForConnected(int msecs) bool wasPendingClose = d->pendingClose; d->pendingClose = false; - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); if (d->state == HostLookupState) { @@ -1819,7 +1819,7 @@ bool QAbstractSocket::waitForReadyRead(int msecs) return false; } - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); // handle a socket in connecting state @@ -1878,7 +1878,7 @@ bool QAbstractSocket::waitForBytesWritten(int msecs) if (d->writeBuffer.isEmpty()) return false; - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); // handle a socket in connecting state @@ -1960,7 +1960,7 @@ bool QAbstractSocket::waitForDisconnected(int msecs) return false; } - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); // handle a socket in connecting state diff --git a/src/network/socket/qhttpsocketengine.cpp b/src/network/socket/qhttpsocketengine.cpp index 3293ff5..dfda257 100644 --- a/src/network/socket/qhttpsocketengine.cpp +++ b/src/network/socket/qhttpsocketengine.cpp @@ -42,9 +42,9 @@ #include "qhttpsocketengine_p.h" #include "qtcpsocket.h" #include "qhostaddress.h" -#include "qdatetime.h" #include "qurl.h" #include "qhttp.h" +#include "qelapsedtimer.h" #if !defined(QT_NO_NETWORKPROXY) && !defined(QT_NO_HTTP) #include <qdebug.h> @@ -319,7 +319,7 @@ bool QHttpSocketEngine::waitForRead(int msecs, bool *timedOut) if (!d->socket || d->socket->state() == QAbstractSocket::UnconnectedState) return false; - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); // Wait for more data if nothing is available. @@ -366,7 +366,7 @@ bool QHttpSocketEngine::waitForWrite(int msecs, bool *timedOut) return true; } - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); // If we're not connected yet, wait until we are, and until bytes have diff --git a/src/network/socket/qlocalsocket_unix.cpp b/src/network/socket/qlocalsocket_unix.cpp index 1ca11d8..f14decc 100644 --- a/src/network/socket/qlocalsocket_unix.cpp +++ b/src/network/socket/qlocalsocket_unix.cpp @@ -52,9 +52,9 @@ #include <fcntl.h> #include <errno.h> -#include <qdatetime.h> #include <qdir.h> #include <qdebug.h> +#include <qelapsedtimer.h> #ifdef Q_OS_VXWORKS # include <selectLib.h> @@ -534,7 +534,7 @@ bool QLocalSocket::waitForConnected(int msec) int result = -1; // on Linux timeout will be updated by select, but _not_ on other systems. - QTime timer; + QElapsedTimer timer; timer.start(); while (state() == ConnectingState && (-1 == msec || timer.elapsed() < msec)) { diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp index 9a2c349..6c800fe 100644 --- a/src/network/socket/qnativesocketengine_unix.cpp +++ b/src/network/socket/qnativesocketengine_unix.cpp @@ -44,8 +44,8 @@ #include "private/qnet_unix_p.h" #include "qiodevice.h" #include "qhostaddress.h" +#include "qelapsedtimer.h" #include "qvarlengtharray.h" -#include "qdatetime.h" #include <time.h> #include <errno.h> #include <fcntl.h> @@ -1003,7 +1003,7 @@ int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool checkRead, bool c #ifndef Q_OS_SYMBIAN ret = qt_safe_select(socketDescriptor + 1, &fdread, &fdwrite, 0, timeout < 0 ? 0 : &tv); #else - QTime timer; + QElapsedTimer timer; timer.start(); do { diff --git a/src/network/socket/qsocks5socketengine.cpp b/src/network/socket/qsocks5socketengine.cpp index 924530e..f68edfe 100644 --- a/src/network/socket/qsocks5socketengine.cpp +++ b/src/network/socket/qsocks5socketengine.cpp @@ -49,7 +49,7 @@ #include "qdebug.h" #include "qhash.h" #include "qqueue.h" -#include "qdatetime.h" +#include "qelapsedtimer.h" #include "qmutex.h" #include "qthread.h" #include "qcoreapplication.h" @@ -308,7 +308,7 @@ struct QSocks5BindData : public QSocks5Data quint16 localPort; QHostAddress peerAddress; quint16 peerPort; - QDateTime timeStamp; + QElapsedTimer timeStamp; }; struct QSocks5RevivedDatagram @@ -369,7 +369,7 @@ void QSocks5BindStore::add(int socketDescriptor, QSocks5BindData *bindData) if (store.contains(socketDescriptor)) { // qDebug() << "delete it"; } - bindData->timeStamp = QDateTime::currentDateTime(); + bindData->timeStamp.start(); store.insert(socketDescriptor, bindData); // start sweep timer if not started if (sweepTimerId == -1) @@ -412,7 +412,7 @@ void QSocks5BindStore::timerEvent(QTimerEvent * event) QMutableHashIterator<int, QSocks5BindData *> it(store); while (it.hasNext()) { it.next(); - if (it.value()->timeStamp.secsTo(QDateTime::currentDateTime()) > 350) { + if (it.value()->timeStamp.hasExpired(350000)) { QSOCKS5_DEBUG << "QSocks5BindStore removing JJJJ"; it.remove(); } @@ -1355,7 +1355,7 @@ bool QSocks5SocketEngine::bind(const QHostAddress &address, quint16 port) } int msecs = SOCKS5_BLOCKING_BIND_TIMEOUT; - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); d->data->controlSocket->connectToHost(d->proxyInfo.hostName(), d->proxyInfo.port()); if (!d->waitForConnected(msecs, 0) || @@ -1455,7 +1455,7 @@ void QSocks5SocketEngine::close() if (d->data && d->data->controlSocket) { if (d->data->controlSocket->state() == QAbstractSocket::ConnectedState) { int msecs = 100; - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); while (!d->data->controlSocket->bytesToWrite()) { if (!d->data->controlSocket->waitForBytesWritten(qt_timeout_value(msecs, stopWatch.elapsed()))) @@ -1674,7 +1674,7 @@ bool QSocks5SocketEnginePrivate::waitForConnected(int msecs, bool *timedOut) mode == BindMode ? BindSuccess : UdpAssociateSuccess; - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); while (socks5State != wantedState) { @@ -1699,7 +1699,7 @@ bool QSocks5SocketEngine::waitForRead(int msecs, bool *timedOut) d->readNotificationActivated = false; - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); // are we connected yet? @@ -1749,7 +1749,7 @@ bool QSocks5SocketEngine::waitForWrite(int msecs, bool *timedOut) Q_D(QSocks5SocketEngine); QSOCKS5_DEBUG << "waitForWrite" << msecs; - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); // are we connected yet? diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp index 9623570..86b11b9 100644 --- a/src/network/ssl/qsslsocket.cpp +++ b/src/network/ssl/qsslsocket.cpp @@ -286,8 +286,8 @@ #include <QtCore/qdebug.h> #include <QtCore/qdir.h> -#include <QtCore/qdatetime.h> #include <QtCore/qmutex.h> +#include <QtCore/qelapsedtimer.h> #include <QtNetwork/qhostaddress.h> #include <QtNetwork/qhostinfo.h> @@ -1393,7 +1393,7 @@ bool QSslSocket::waitForEncrypted(int msecs) if (d->mode == UnencryptedMode && !d->autoStartHandshake) return false; - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); if (d->plainSocket->state() != QAbstractSocket::ConnectedState) { @@ -1433,7 +1433,7 @@ bool QSslSocket::waitForReadyRead(int msecs) bool *previousReadyReadEmittedPointer = d->readyReadEmittedPointer; d->readyReadEmittedPointer = &readyReadEmitted; - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); if (!d->connectionEncrypted) { @@ -1470,7 +1470,7 @@ bool QSslSocket::waitForBytesWritten(int msecs) if (d->mode == UnencryptedMode) return d->plainSocket->waitForBytesWritten(msecs); - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); if (!d->connectionEncrypted) { @@ -1508,7 +1508,7 @@ bool QSslSocket::waitForDisconnected(int msecs) if (d->mode == UnencryptedMode) return d->plainSocket->waitForDisconnected(msecs); - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); if (!d->connectionEncrypted) { |