summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@nokia.com>2010-02-17 06:16:55 (GMT)
committerAaron McCarthy <aaron.mccarthy@nokia.com>2010-03-19 02:11:19 (GMT)
commit39818f933b958d504b9cc18487658209d1df22da (patch)
treeb88fcbfbfda7d57866bab0e391360521c3f87af0
parent777843c18c9b62af90436ba03036027c9222eadf (diff)
downloadQt-39818f933b958d504b9cc18487658209d1df22da.zip
Qt-39818f933b958d504b9cc18487658209d1df22da.tar.gz
Qt-39818f933b958d504b9cc18487658209d1df22da.tar.bz2
Don't emit open signal on session close/error.
-rw-r--r--src/network/access/qnetworkaccessmanager.cpp2
-rw-r--r--src/network/access/qnetworkreplyimpl.cpp10
-rw-r--r--src/network/access/qnetworkreplyimpl_p.h2
-rw-r--r--src/network/bearer/qnetworksession.cpp9
-rw-r--r--src/network/bearer/qnetworksession_p.h4
-rw-r--r--src/plugins/bearer/qnetworksession_impl.cpp19
-rw-r--r--src/plugins/bearer/qnetworksession_impl.h2
-rw-r--r--tests/auto/qnetworksession/test/tst_qnetworksession.cpp3
8 files changed, 33 insertions, 18 deletions
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index 51c5731..f52eec5 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -914,6 +914,8 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
if (req.url().scheme() != QLatin1String("file") && !req.url().scheme().isEmpty()) {
connect(this, SIGNAL(networkSessionConnected()),
reply, SLOT(_q_networkSessionConnected()));
+ if (d->networkSession)
+ connect(d->networkSession, SIGNAL(closed()), reply, SLOT(_q_networkSessionClosed()));
}
QNetworkReplyImplPrivate *priv = reply->d_func();
priv->manager = this;
diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp
index 7fc0097..9ef2ed8 100644
--- a/src/network/access/qnetworkreplyimpl.cpp
+++ b/src/network/access/qnetworkreplyimpl.cpp
@@ -262,6 +262,16 @@ void QNetworkReplyImplPrivate::_q_networkSessionConnected()
}
}
+void QNetworkReplyImplPrivate::_q_networkSessionClosed()
+{
+ if (state != Finished) {
+ state = Working;
+ error(QNetworkReply::UnknownNetworkError,
+ QCoreApplication::translate("QNetworkReply", "Network session closed."));
+ finished();
+ }
+}
+
void QNetworkReplyImplPrivate::_q_networkSessionFailed()
{
// Abort waiting replies.
diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h
index fcb3397..8e498d5 100644
--- a/src/network/access/qnetworkreplyimpl_p.h
+++ b/src/network/access/qnetworkreplyimpl_p.h
@@ -100,6 +100,7 @@ public:
Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingData())
Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingDataFinished())
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionConnected())
+ Q_PRIVATE_SLOT(d_func(), void _q_networkSessionClosed())
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionFailed())
};
@@ -134,6 +135,7 @@ public:
void _q_bufferOutgoingData();
void _q_bufferOutgoingDataFinished();
void _q_networkSessionConnected();
+ void _q_networkSessionClosed();
void _q_networkSessionFailed();
void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request,
diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp
index cf9f4b2..d05f20e 100644
--- a/src/network/bearer/qnetworksession.cpp
+++ b/src/network/bearer/qnetworksession.cpp
@@ -231,7 +231,7 @@ QNetworkSession::QNetworkSession(const QNetworkConfiguration& connectionConfig,
d->q = this;
d->publicConfig = connectionConfig;
d->syncStateWithInterface();
- connect(d, SIGNAL(quitPendingWaitsForOpened()), this, SIGNAL(opened()));
+ connect(d, SIGNAL(opened()), this, SIGNAL(opened()));
connect(d, SIGNAL(error(QNetworkSession::SessionError)),
this, SIGNAL(error(QNetworkSession::SessionError)));
connect(d, SIGNAL(stateChanged(QNetworkSession::State)),
@@ -308,10 +308,9 @@ bool QNetworkSession::waitForOpened(int msecs)
return false;
QEventLoop* loop = new QEventLoop(this);
- QObject::connect(d, SIGNAL(quitPendingWaitsForOpened()),
- loop, SLOT(quit()));
- QObject::connect(this, SIGNAL(error(QNetworkSession::SessionError)),
- loop, SLOT(quit()));
+ connect(d, SIGNAL(opened()), loop, SLOT(quit()));
+ connect(d, SIGNAL(closed()), loop, SLOT(quit()));
+ connect(d, SIGNAL(error(QNetworkSession::SessionError)), loop, SLOT(quit()));
//final call
if (msecs>=0)
diff --git a/src/network/bearer/qnetworksession_p.h b/src/network/bearer/qnetworksession_p.h
index 76691b3..5eef8e3 100644
--- a/src/network/bearer/qnetworksession_p.h
+++ b/src/network/bearer/qnetworksession_p.h
@@ -116,9 +116,7 @@ protected:
}
Q_SIGNALS:
- //releases any pending waitForOpened() calls
- void quitPendingWaitsForOpened();
-
+ void opened();
void error(QNetworkSession::SessionError error);
void stateChanged(QNetworkSession::State state);
void closed();
diff --git a/src/plugins/bearer/qnetworksession_impl.cpp b/src/plugins/bearer/qnetworksession_impl.cpp
index db1759c..ddda04f 100644
--- a/src/plugins/bearer/qnetworksession_impl.cpp
+++ b/src/plugins/bearer/qnetworksession_impl.cpp
@@ -103,7 +103,7 @@ void QNetworkSessionPrivateImpl::syncStateWithInterface()
connect(sessionManager(), SIGNAL(forcedSessionClose(QNetworkConfiguration)),
this, SLOT(forcedSessionClose(QNetworkConfiguration)));
- opened = false;
+ sessionOpened = false;
isOpen = false;
state = QNetworkSession::Invalid;
lastError = QNetworkSession::UnknownSessionError;
@@ -153,7 +153,7 @@ void QNetworkSessionPrivateImpl::open()
emit QNetworkSessionPrivate::error(lastError);
return;
}
- opened = true;
+ sessionOpened = true;
if ((activeConfig.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active &&
(activeConfig.state() & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) {
@@ -165,7 +165,7 @@ void QNetworkSessionPrivateImpl::open()
isOpen = (activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active;
if (isOpen)
- emit quitPendingWaitsForOpened();
+ emit opened();
}
}
@@ -175,7 +175,7 @@ void QNetworkSessionPrivateImpl::close()
lastError = QNetworkSession::OperationNotSupportedError;
emit QNetworkSessionPrivate::error(lastError);
} else if (isOpen) {
- opened = false;
+ sessionOpened = false;
isOpen = false;
emit closed();
}
@@ -196,7 +196,7 @@ void QNetworkSessionPrivateImpl::stop()
sessionManager()->forceSessionClose(activeConfig);
}
- opened = false;
+ sessionOpened = false;
isOpen = false;
emit closed();
}
@@ -364,10 +364,10 @@ void QNetworkSessionPrivateImpl::updateStateFromActiveConfig()
state = engine->sessionStateForId(activeConfig.identifier());
bool oldActive = isOpen;
- isOpen = (state == QNetworkSession::Connected) ? opened : false;
+ isOpen = (state == QNetworkSession::Connected) ? sessionOpened : false;
if (!oldActive && isOpen)
- emit quitPendingWaitsForOpened();
+ emit opened();
if (oldActive && !isOpen)
emit closed();
@@ -398,7 +398,7 @@ void QNetworkSessionPrivateImpl::configurationChanged(QNetworkConfigurationPriva
void QNetworkSessionPrivateImpl::forcedSessionClose(const QNetworkConfiguration &config)
{
if (activeConfig == config) {
- opened = false;
+ sessionOpened = false;
isOpen = false;
emit closed();
@@ -416,7 +416,7 @@ void QNetworkSessionPrivateImpl::connectionError(const QString &id,
switch (error) {
case QBearerEngineImpl::OperationNotSupported:
lastError = QNetworkSession::OperationNotSupportedError;
- opened = false;
+ sessionOpened = false;
break;
case QBearerEngineImpl::InterfaceLookupError:
case QBearerEngineImpl::ConnectError:
@@ -426,6 +426,7 @@ void QNetworkSessionPrivateImpl::connectionError(const QString &id,
}
emit QNetworkSessionPrivate::error(lastError);
+ emit closed();
}
}
diff --git a/src/plugins/bearer/qnetworksession_impl.h b/src/plugins/bearer/qnetworksession_impl.h
index c644174..c31e540 100644
--- a/src/plugins/bearer/qnetworksession_impl.h
+++ b/src/plugins/bearer/qnetworksession_impl.h
@@ -114,7 +114,7 @@ private Q_SLOTS:
void decrementTimeout();
private:
- bool opened;
+ bool sessionOpened;
QBearerEngineImpl *engine;
diff --git a/tests/auto/qnetworksession/test/tst_qnetworksession.cpp b/tests/auto/qnetworksession/test/tst_qnetworksession.cpp
index 4b56f77..35f7ba7 100644
--- a/tests/auto/qnetworksession/test/tst_qnetworksession.cpp
+++ b/tests/auto/qnetworksession/test/tst_qnetworksession.cpp
@@ -628,6 +628,9 @@ void tst_QNetworkSession::sessionOpenCloseStop()
QVERIFY(session.state() == previousState);
+ QVERIFY(sessionOpenedSpy.isEmpty());
+ QCOMPARE(sessionClosedSpy.count(), 1);
+
if (error == QNetworkSession::OperationNotSupportedError) {
// The session needed to bring up the interface,
// but the operation is not supported.