diff options
author | Shane Kearns <shane.kearns@accenture.com> | 2011-06-07 14:38:38 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-06-22 11:01:00 +0200 |
commit | 85136496bc8517951dcc3e670d1a46d340819f0d (patch) | |
tree | 86ca9423d926ed2f85744f4159966549f454e8f8 /tests/auto/qtcpserver/tst_qtcpserver.cpp | |
parent | 665d8a045455214d2cfca72076da6bc75d3058c7 (diff) |
IPv4 + IPv6 dual stack sockets
Adds support for binding "dual stack" sockets (via QUdpSocket or
QTcpServer). A dual stack socket will accept incoming connections on
either IPv4 or IPv6 interfaces.
QHostAddress::Any - use this to bind a dual stack socket
QHostAddress::AnyIPv6 - use this to bind a socket for IPv6 only
QHostAddress::AnyIPv4 - use this to bind a socket for IPv4 only
Binding to a specific address rather than one of the "any" addresses
is restricting you to a protocol anyway so no behaviour change there.
IPv6 sockets were previously dual stack on some OS and v6 only on others
Any previously meant IPv4 only
This commit implemented & tested on Windows 7, Linux (Ubuntu 10.04)
and Mac OS 10.6.7.
Windows XP and server 2003 do not support dual stack sockets, even though
they can support IPv6. On those versions, QHostAddress::Any will still
bind to IPv4 0.0.0.0 (which is also the behaviour anywhere QT_NO_IPV6 is
defined)
Autotests run:
qudpsocket (includes a new test case)
qtcpserver (includes a new test case)
qtcpsocket
qnetworkreply
qhostaddress
Task-number: QTBUG-17080
Change-Id: Id486677c4f832e18dc0ff1a86c5f5fc422c9eb4f
Reviewed-on: http://codereview.qt.nokia.com/421
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Thiago Macieira <thiago.macieira@nokia.com>
Reviewed-by: Markus Goetz
Diffstat (limited to 'tests/auto/qtcpserver/tst_qtcpserver.cpp')
-rw-r--r-- | tests/auto/qtcpserver/tst_qtcpserver.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/auto/qtcpserver/tst_qtcpserver.cpp b/tests/auto/qtcpserver/tst_qtcpserver.cpp index 3416a7cb23..beeb6c7655 100644 --- a/tests/auto/qtcpserver/tst_qtcpserver.cpp +++ b/tests/auto/qtcpserver/tst_qtcpserver.cpp @@ -97,6 +97,8 @@ private slots: void constructing(); void clientServerLoop(); void ipv6Server(); + void dualStack_data(); + void dualStack(); void ipv6ServerMapped(); void crashTests(); void maxPendingConnections(); @@ -265,6 +267,44 @@ void tst_QTcpServer::ipv6Server() delete serverSocket; } +Q_DECLARE_METATYPE(QHostAddress); + +void tst_QTcpServer::dualStack_data() +{ + QTest::addColumn<QHostAddress>("bindAddress"); + QTest::addColumn<bool>("v4ok"); + QTest::addColumn<bool>("v6ok"); + QTest::newRow("any") << QHostAddress(QHostAddress::Any) << true << true; + QTest::newRow("anyIPv4") << QHostAddress(QHostAddress::AnyIPv4) << true << false; + QTest::newRow("anyIPv6") << QHostAddress(QHostAddress::AnyIPv6) << false << true; +} + +void tst_QTcpServer::dualStack() +{ +#ifdef QT_NO_IPV6 + QSKIP("test requires IPv6 support", SkipAll); +#else + QFETCH_GLOBAL(bool, setProxy); + if (setProxy) + QSKIP("test server proxy doesn't support ipv6", SkipSingle); + QFETCH(QHostAddress, bindAddress); + QFETCH(bool, v4ok); + QFETCH(bool, v6ok); + + QTcpServer server; + QVERIFY(server.listen(bindAddress)); + + QTcpSocket v4client; + v4client.connectToHost(QHostAddress::LocalHost, server.serverPort()); + + QTcpSocket v6client; + v6client.connectToHost(QHostAddress::LocalHostIPv6, server.serverPort()); + + QCOMPARE(v4client.waitForConnected(5000), v4ok); + QCOMPARE(v6client.waitForConnected(5000), v6ok); +#endif +} + //---------------------------------------------------------------------------------- void tst_QTcpServer::ipv6ServerMapped() { |