summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2014-12-23 13:37:01 -0200
committerThiago Macieira <thiago.macieira@intel.com>2015-03-04 23:58:03 +0000
commit9fb68a90af79df3b8dc3225a3a97e2c6387afeec (patch)
treeb51f4ca6effbcf2da792595837a92198a2181f01 /tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
parent29051bce39d24a6e33155feeec2833b79b55ff16 (diff)
Fix bind+connect in both TCP and UDP
This has been known to be broken for a while. Now it works: you can bind and you'll retain the port (and the file descriptor) for the connect call. Incidentally, in fixing the binding for more than one IP for the hostname (with event loop), this commit fixes the setSocketDescriptor XFAIL. [ChangeLog][QtNetwork] Fixed a bug that caused both QTcpSocket and QUdpSocket to close the socket and lose any bound ports before connecting. Now bind()/setSocketDescriptor() followed by connect() will retain the original file descriptor. Task-number: QTBUG-26538 Change-Id: I691caed7e8fd16a9cf687b5995afbf3006bf453a Reviewed-by: Richard J. Moore <rich@kde.org>
Diffstat (limited to 'tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp')
-rw-r--r--tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp36
1 files changed, 34 insertions, 2 deletions
diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
index 76d4543da9..4bd330b04f 100644
--- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
+++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
@@ -85,7 +85,8 @@ private slots:
void dualStack();
void dualStackAutoBinding();
void dualStackNoIPv4onV6only();
- void readLine();
+ void connectToHost();
+ void bindAndConnectToHost();
void pendingDatagramSize();
void writeDatagram();
void performance();
@@ -621,7 +622,7 @@ void tst_QUdpSocket::empty_connectedSlot()
//----------------------------------------------------------------------------------
-void tst_QUdpSocket::readLine()
+void tst_QUdpSocket::connectToHost()
{
QUdpSocket socket1;
QUdpSocket socket2;
@@ -629,10 +630,41 @@ void tst_QUdpSocket::readLine()
socket1.setProperty("_q_networksession", QVariant::fromValue(networkSession));
socket2.setProperty("_q_networksession", QVariant::fromValue(networkSession));
#endif
+
+ QVERIFY2(socket1.bind(), socket1.errorString().toLatin1().constData());
+
+ socket2.connectToHost(makeNonAny(socket1.localAddress()), socket1.localPort());
+ QVERIFY(socket2.waitForConnected(5000));
+}
+
+//----------------------------------------------------------------------------------
+
+void tst_QUdpSocket::bindAndConnectToHost()
+{
+ QUdpSocket socket1;
+ QUdpSocket socket2;
+ QUdpSocket dummysocket;
+#ifdef FORCE_SESSION
+ socket1.setProperty("_q_networksession", QVariant::fromValue(networkSession));
+ socket2.setProperty("_q_networksession", QVariant::fromValue(networkSession));
+ dummysocket.setProperty("_q_networksession", QVariant::fromValue(networkSession));
+#endif
+
+ // we use the dummy socket to use up a file descriptor
+ dummysocket.bind();
+
+ QVERIFY2(socket2.bind(), socket2.errorString().toLatin1());
+ quint16 boundPort = socket2.localPort();
+ qintptr fd = socket2.socketDescriptor();
+
QVERIFY2(socket1.bind(), socket1.errorString().toLatin1().constData());
+ dummysocket.close();
socket2.connectToHost(makeNonAny(socket1.localAddress()), socket1.localPort());
QVERIFY(socket2.waitForConnected(5000));
+
+ QCOMPARE(socket2.localPort(), boundPort);
+ QCOMPARE(socket2.socketDescriptor(), fd);
}
//----------------------------------------------------------------------------------