summaryrefslogtreecommitdiffstats
path: root/tests/auto/network
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2015-12-23 13:10:30 +0200
committerAlex Trotsenko <alex1973tr@gmail.com>2015-12-24 14:05:26 +0000
commit6b6955c2ffdb23c461812ffcda12a2296ef58513 (patch)
tree65c09464b1a43d4c25c06e87498bc93b2bcd2c43 /tests/auto/network
parent1e2d35d4880574b20537677729093df279658965 (diff)
QAbstractSocket: do not enable read notifications on TCP in bind()
In bind+connect scenario, rejected connection can trigger a read notification while the socket is opened. But unlike UDP, reading from the socket engine or emitting a readyRead() signal is not allowed for the TCP socket in bound or connecting state. To make a bind+connect scenario work properly, disable the read notifications until a connection is established. Task-number: QTBUG-50124 Change-Id: I7b3d015b0f6021fb9ff9f83560478aa5545f41f5 Reviewed-by: Richard J. Moore <rich@kde.org>
Diffstat (limited to 'tests/auto/network')
-rw-r--r--tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
index 0ba9b6a58c..e8a942e6c4 100644
--- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
+++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
@@ -200,6 +200,7 @@ private slots:
void setSocketOption();
void clientSendDataOnDelayedDisconnect();
+ void readNotificationsAfterBind();
protected slots:
void nonBlockingIMAP_hostFound();
@@ -2984,5 +2985,25 @@ void tst_QTcpSocket::clientSendDataOnDelayedDisconnect()
delete socket;
}
+// Test that the socket does not enable the read notifications in bind()
+void tst_QTcpSocket::readNotificationsAfterBind()
+{
+ QFETCH_GLOBAL(bool, setProxy);
+ if (setProxy)
+ return;
+
+ QAbstractSocket socket(QAbstractSocket::TcpSocket, Q_NULLPTR);
+ QVERIFY2(socket.bind(), "Bind error!");
+
+ connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ QSignalSpy spyReadyRead(&socket, SIGNAL(readyRead()));
+ socket.connectToHost(QtNetworkSettings::serverName(), 12346);
+
+ QTestEventLoop::instance().enterLoop(10);
+ QVERIFY2(!QTestEventLoop::instance().timeout(), "Connection to closed port timed out instead of refusing, something is wrong");
+ QVERIFY2(socket.state() == QAbstractSocket::UnconnectedState, "Socket connected unexpectedly!");
+ QCOMPARE(spyReadyRead.count(), 0);
+}
+
QTEST_MAIN(tst_QTcpSocket)
#include "tst_qtcpsocket.moc"