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>
This commit is contained in:
parent
e5785d6322
commit
eb0032687f
@ -530,7 +530,7 @@ class MiniHttpServer: public QTcpServer
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
QTcpSocket *client; // always the last one that was received
|
QPointer<QTcpSocket> client; // always the last one that was received
|
||||||
QByteArray dataToTransmit;
|
QByteArray dataToTransmit;
|
||||||
QByteArray receivedData;
|
QByteArray receivedData;
|
||||||
QSemaphore ready;
|
QSemaphore ready;
|
||||||
@ -541,7 +541,7 @@ public:
|
|||||||
int totalConnections;
|
int totalConnections;
|
||||||
|
|
||||||
MiniHttpServer(const QByteArray &data, bool ssl = false, QThread *thread = 0, bool useipv6 = false)
|
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)
|
multiple(false), totalConnections(0)
|
||||||
{
|
{
|
||||||
if (useipv6) {
|
if (useipv6) {
|
||||||
@ -591,6 +591,7 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void reply() {
|
virtual void reply() {
|
||||||
|
Q_ASSERT(!client.isNull());
|
||||||
// we need to emulate the bytesWrittenSlot call if the data is empty.
|
// we need to emulate the bytesWrittenSlot call if the data is empty.
|
||||||
if (dataToTransmit.size() == 0)
|
if (dataToTransmit.size() == 0)
|
||||||
QMetaObject::invokeMethod(this, "bytesWrittenSlot", Qt::QueuedConnection);
|
QMetaObject::invokeMethod(this, "bytesWrittenSlot", Qt::QueuedConnection);
|
||||||
@ -600,10 +601,11 @@ protected:
|
|||||||
private:
|
private:
|
||||||
void connectSocketSignals()
|
void connectSocketSignals()
|
||||||
{
|
{
|
||||||
|
Q_ASSERT(!client.isNull());
|
||||||
//qDebug() << "connectSocketSignals" << client;
|
//qDebug() << "connectSocketSignals" << client;
|
||||||
connect(client, SIGNAL(readyRead()), this, SLOT(readyReadSlot()));
|
connect(client.data(), SIGNAL(readyRead()), this, SLOT(readyReadSlot()));
|
||||||
connect(client, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWrittenSlot()));
|
connect(client.data(), SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWrittenSlot()));
|
||||||
connect(client, SIGNAL(error(QAbstractSocket::SocketError)),
|
connect(client.data(), SIGNAL(error(QAbstractSocket::SocketError)),
|
||||||
this, SLOT(slotError(QAbstractSocket::SocketError)));
|
this, SLOT(slotError(QAbstractSocket::SocketError)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -611,17 +613,20 @@ private slots:
|
|||||||
#ifndef QT_NO_SSL
|
#ifndef QT_NO_SSL
|
||||||
void slotSslErrors(const QList<QSslError>& errors)
|
void slotSslErrors(const QList<QSslError>& errors)
|
||||||
{
|
{
|
||||||
|
Q_ASSERT(!client.isNull());
|
||||||
qDebug() << "slotSslErrors" << client->errorString() << errors;
|
qDebug() << "slotSslErrors" << client->errorString() << errors;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
void slotError(QAbstractSocket::SocketError err)
|
void slotError(QAbstractSocket::SocketError err)
|
||||||
{
|
{
|
||||||
|
Q_ASSERT(!client.isNull());
|
||||||
qDebug() << "slotError" << err << client->errorString();
|
qDebug() << "slotError" << err << client->errorString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void readyReadSlot()
|
void readyReadSlot()
|
||||||
{
|
{
|
||||||
|
Q_ASSERT(!client.isNull());
|
||||||
receivedData += client->readAll();
|
receivedData += client->readAll();
|
||||||
int doubleEndlPos = receivedData.indexOf("\r\n\r\n");
|
int doubleEndlPos = receivedData.indexOf("\r\n\r\n");
|
||||||
|
|
||||||
@ -635,9 +640,11 @@ public slots:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void bytesWrittenSlot() {
|
void bytesWrittenSlot() {
|
||||||
|
Q_ASSERT(!client.isNull());
|
||||||
|
// Disconnect and delete in next cycle (else Windows clients will fail with RemoteHostClosedError).
|
||||||
if (doClose && client->bytesToWrite() == 0) {
|
if (doClose && client->bytesToWrite() == 0) {
|
||||||
client->disconnectFromHost();
|
|
||||||
disconnect(client, 0, this, 0);
|
disconnect(client, 0, this, 0);
|
||||||
|
client->deleteLater();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user