summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2014-09-24 18:45:42 +0300
committerAlex Trotsenko <alex1973tr@gmail.com>2015-02-11 21:19:13 +0000
commit071716f2daebaebab562b7f49c29f281c5536bbc (patch)
tree44b80edfc27b7875ac182ca180ec64b758276791
parent2688725eb73234a8870411017f85ec2fda6c80cd (diff)
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>
-rw-r--r--src/network/socket/qabstractsocket.cpp15
-rw-r--r--src/network/socket/qabstractsocket_p.h1
-rw-r--r--tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp34
3 files changed, 35 insertions, 15 deletions
diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp
index 2557213420..76874823f0 100644
--- a/src/network/socket/qabstractsocket.cpp
+++ b/src/network/socket/qabstractsocket.cpp
@@ -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();
- }
}
/*!
diff --git a/src/network/socket/qabstractsocket_p.h b/src/network/socket/qabstractsocket_p.h
index 218f93a504..379657f4fa 100644
--- a/src/network/socket/qabstractsocket_p.h
+++ b/src/network/socket/qabstractsocket_p.h
@@ -97,7 +97,6 @@ public:
bool emittedBytesWritten;
bool abortCalled;
- bool closeCalled;
bool pendingClose;
QAbstractSocket::PauseModes pauseMode;
diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
index 8bbbf79633..f9e02b40f6 100644
--- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
+++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
@@ -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"