QAbstractSocket: remove unneeded cleanup calls and private member
QAbstractSocket::close() always calls QIODevice::close(), which resets QIODevice's internal read buffer. So it makes no sense to make same calls from disconnectFromHost(). This made the closeCalled private member superfluous. Change-Id: I4ec64e9711490e44e737763e4ed7fb41bffe2556 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
2688725eb7
commit
071716f2da
|
|
@ -549,7 +549,6 @@ QAbstractSocketPrivate::QAbstractSocketPrivate()
|
|||
emittedReadyRead(false),
|
||||
emittedBytesWritten(false),
|
||||
abortCalled(false),
|
||||
closeCalled(false),
|
||||
pendingClose(false),
|
||||
pauseMode(QAbstractSocket::PauseNever),
|
||||
port(0),
|
||||
|
|
@ -1610,7 +1609,6 @@ void QAbstractSocket::connectToHost(const QString &hostName, quint16 port,
|
|||
d->buffer.clear();
|
||||
d->writeBuffer.clear();
|
||||
d->abortCalled = false;
|
||||
d->closeCalled = false;
|
||||
d->pendingClose = false;
|
||||
d->localPort = 0;
|
||||
d->peerPort = 0;
|
||||
|
|
@ -2650,10 +2648,8 @@ void QAbstractSocket::close()
|
|||
qDebug("QAbstractSocket::close()");
|
||||
#endif
|
||||
QIODevice::close();
|
||||
if (d->state != UnconnectedState) {
|
||||
d->closeCalled = true;
|
||||
if (d->state != UnconnectedState)
|
||||
disconnectFromHost();
|
||||
}
|
||||
|
||||
d->localPort = 0;
|
||||
d->peerPort = 0;
|
||||
|
|
@ -2763,19 +2759,12 @@ void QAbstractSocket::disconnectFromHost()
|
|||
d->peerPort = 0;
|
||||
d->localAddress.clear();
|
||||
d->peerAddress.clear();
|
||||
d->writeBuffer.clear();
|
||||
|
||||
#if defined(QABSTRACTSOCKET_DEBUG)
|
||||
qDebug("QAbstractSocket::disconnectFromHost() disconnected!");
|
||||
#endif
|
||||
|
||||
if (d->closeCalled) {
|
||||
#if defined(QABSTRACTSOCKET_DEBUG)
|
||||
qDebug("QAbstractSocket::disconnectFromHost() closed!");
|
||||
#endif
|
||||
d->buffer.clear();
|
||||
d->writeBuffer.clear();
|
||||
QIODevice::close();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -97,7 +97,6 @@ public:
|
|||
bool emittedBytesWritten;
|
||||
|
||||
bool abortCalled;
|
||||
bool closeCalled;
|
||||
bool pendingClose;
|
||||
|
||||
QAbstractSocket::PauseModes pauseMode;
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ private slots:
|
|||
void qtbug14268_peek();
|
||||
|
||||
void setSocketOption();
|
||||
|
||||
void clientSendDataOnDelayedDisconnect();
|
||||
|
||||
protected slots:
|
||||
void nonBlockingIMAP_hostFound();
|
||||
|
|
@ -2815,5 +2815,37 @@ void tst_QTcpSocket::setSocketOption()
|
|||
QVERIFY(v.isValid() && v.toInt() == 32);
|
||||
}
|
||||
|
||||
// Test buffered socket properly send data on delayed disconnect
|
||||
void tst_QTcpSocket::clientSendDataOnDelayedDisconnect()
|
||||
{
|
||||
QFETCH_GLOBAL(bool, setProxy);
|
||||
if (setProxy)
|
||||
return;
|
||||
|
||||
QTcpServer server;
|
||||
QTcpSocket *socket = newSocket();
|
||||
|
||||
QVERIFY(server.listen(QHostAddress::LocalHost));
|
||||
|
||||
// Connect to server, write data and close socket
|
||||
const QByteArray sendData("GET /\r\n");
|
||||
socket->connectToHost(server.serverAddress(), server.serverPort());
|
||||
QVERIFY(socket->waitForConnected(5000)); // ready for write
|
||||
QCOMPARE(socket->write(sendData), sendData.size());
|
||||
socket->close();
|
||||
QVERIFY(socket->waitForDisconnected(5000)); // flush buffer
|
||||
|
||||
// Check data on server side
|
||||
QByteArray recData;
|
||||
QVERIFY(server.waitForNewConnection(5000));
|
||||
QTcpSocket *newConnection = server.nextPendingConnection();
|
||||
QVERIFY(newConnection != NULL);
|
||||
while (newConnection->waitForReadyRead(5000)) // have data to read
|
||||
recData += newConnection->readAll();
|
||||
QCOMPARE(sendData, recData);
|
||||
|
||||
delete socket;
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QTcpSocket)
|
||||
#include "tst_qtcpsocket.moc"
|
||||
|
|
|
|||
Loading…
Reference in New Issue