diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-03-12 12:38:32 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-13 13:25:35 +0100 |
commit | eb0032687fd6a107bcd3dcff719a1ca761c87971 (patch) | |
tree | d61c8b1a49023ee1f953bf1b55046f536b50c3cb /tests | |
parent | e5785d6322051ba96b1a4a97963a64c1aabbc027 (diff) |
Stabilize tst_qnetworkreply on Windows.
Do not close connection in slot bytesWritten() since that can
cause clients to fail with "Connection Closed". Instead, use
deleteLater() to close properly and prevent leaking the sockets.
FAIL! : tst_QNetworkReply::qtbug28035browserDoesNotLoadQtProjectOrgCorrectly() 'waitForFinish(reply) == Success' returned FALSE. ( QUrl( "http://localhost:58240" ) failed: # 2 "Connection closed" )
..\tst_qnetworkreply.cpp(7067) : failure location
Task-number: QTBUG-37449
Change-Id: Ib92cb62fae523370b2fb45e1ccfa217559732bc8
Reviewed-by: Peter Hartmann <phartmann@blackberry.com>
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index c883b77ea8..c448e89375 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -530,7 +530,7 @@ class MiniHttpServer: public QTcpServer { Q_OBJECT public: - QTcpSocket *client; // always the last one that was received + QPointer<QTcpSocket> client; // always the last one that was received QByteArray dataToTransmit; QByteArray receivedData; QSemaphore ready; @@ -541,7 +541,7 @@ public: int totalConnections; MiniHttpServer(const QByteArray &data, bool ssl = false, QThread *thread = 0, bool useipv6 = false) - : client(0), dataToTransmit(data), doClose(true), doSsl(ssl), ipv6(useipv6), + : dataToTransmit(data), doClose(true), doSsl(ssl), ipv6(useipv6), multiple(false), totalConnections(0) { if (useipv6) { @@ -591,6 +591,7 @@ protected: } virtual void reply() { + Q_ASSERT(!client.isNull()); // we need to emulate the bytesWrittenSlot call if the data is empty. if (dataToTransmit.size() == 0) QMetaObject::invokeMethod(this, "bytesWrittenSlot", Qt::QueuedConnection); @@ -600,10 +601,11 @@ protected: private: void connectSocketSignals() { + Q_ASSERT(!client.isNull()); //qDebug() << "connectSocketSignals" << client; - connect(client, SIGNAL(readyRead()), this, SLOT(readyReadSlot())); - connect(client, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWrittenSlot())); - connect(client, SIGNAL(error(QAbstractSocket::SocketError)), + connect(client.data(), SIGNAL(readyRead()), this, SLOT(readyReadSlot())); + connect(client.data(), SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWrittenSlot())); + connect(client.data(), SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotError(QAbstractSocket::SocketError))); } @@ -611,17 +613,20 @@ private slots: #ifndef QT_NO_SSL void slotSslErrors(const QList<QSslError>& errors) { + Q_ASSERT(!client.isNull()); qDebug() << "slotSslErrors" << client->errorString() << errors; } #endif void slotError(QAbstractSocket::SocketError err) { + Q_ASSERT(!client.isNull()); qDebug() << "slotError" << err << client->errorString(); } public slots: void readyReadSlot() { + Q_ASSERT(!client.isNull()); receivedData += client->readAll(); int doubleEndlPos = receivedData.indexOf("\r\n\r\n"); @@ -635,9 +640,11 @@ public slots: } void bytesWrittenSlot() { + Q_ASSERT(!client.isNull()); + // Disconnect and delete in next cycle (else Windows clients will fail with RemoteHostClosedError). if (doClose && client->bytesToWrite() == 0) { - client->disconnectFromHost(); disconnect(client, 0, this, 0); + client->deleteLater(); } } |