summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorShane Kearns <ext-shane.2.kearns@nokia.com>2012-03-15 17:58:22 +0000
committerQt by Nokia <qt-info@nokia.com>2012-03-22 18:59:45 +0100
commitcae5299f48d950ab924e8b78452d25535bd8b811 (patch)
treebba1f53b34cbd2b1ffbb8ef9368b7a1f2ed6f9aa /src
parentfa8e18c3860d8c43795152da1d4c38dc1471f320 (diff)
Allow autobound UDP sockets to send to IPv4 and IPv6
When writeDatagram is called without first binding the UDP socket, then bind it as QHostAddress::Any. This allows the same socket to be used to sent to both IPv4 and IPv6 destination addresses. Allowing the OS to autobind the socket inside sendTo() may result in a single protocol socket. Task-number: QTBUG-5275 Change-Id: I2b76507e8a8a38369c6eafb61ce4191d1d6cc930 Reviewed-by: Richard J. Moore <rich@kde.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Martin Petersson <Martin.Petersson@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/network/socket/qnativesocketengine_unix.cpp3
-rw-r--r--src/network/socket/qnativesocketengine_win.cpp3
-rw-r--r--src/network/socket/qudpsocket.cpp4
3 files changed, 7 insertions, 3 deletions
diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp
index b7c149c18d..295d3961a8 100644
--- a/src/network/socket/qnativesocketengine_unix.cpp
+++ b/src/network/socket/qnativesocketengine_unix.cpp
@@ -854,7 +854,8 @@ qint64 QNativeSocketEnginePrivate::nativeSendDatagram(const char *data, qint64 l
struct sockaddr_in6 sockAddrIPv6;
if (host.protocol() == QAbstractSocket::IPv6Protocol
- || socketProtocol == QAbstractSocket::IPv6Protocol) {
+ || socketProtocol == QAbstractSocket::IPv6Protocol
+ || socketProtocol == QAbstractSocket::AnyIPProtocol) {
memset(&sockAddrIPv6, 0, sizeof(sockAddrIPv6));
sockAddrIPv6.sin6_family = AF_INET6;
sockAddrIPv6.sin6_port = htons(port);
diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp
index 93a470c77f..4bf2a6c6e3 100644
--- a/src/network/socket/qnativesocketengine_win.cpp
+++ b/src/network/socket/qnativesocketengine_win.cpp
@@ -202,7 +202,8 @@ void QNativeSocketEnginePrivate::setPortAndAddress(sockaddr_in * sockAddrIPv4, q
if (address.protocol() == QAbstractSocket::IPv6Protocol
|| address.protocol() == QAbstractSocket::AnyIPProtocol
- || socketProtocol == QAbstractSocket::IPv6Protocol) {
+ || socketProtocol == QAbstractSocket::IPv6Protocol
+ || socketProtocol == QAbstractSocket::AnyIPProtocol) {
memset(sockAddrIPv6, 0, sizeof(qt_sockaddr_in6));
sockAddrIPv6->sin6_family = AF_INET6;
sockAddrIPv6->sin6_scope_id = address.scopeId().toInt();
diff --git a/src/network/socket/qudpsocket.cpp b/src/network/socket/qudpsocket.cpp
index a31b16e97d..ec751c289e 100644
--- a/src/network/socket/qudpsocket.cpp
+++ b/src/network/socket/qudpsocket.cpp
@@ -332,8 +332,10 @@ qint64 QUdpSocket::writeDatagram(const char *data, qint64 size, const QHostAddre
qDebug("QUdpSocket::writeDatagram(%p, %llu, \"%s\", %i)", data, size,
address.toString().toLatin1().constData(), port);
#endif
- if (!d->ensureInitialized(address))
+ if (!d->doEnsureInitialized(QHostAddress::Any, 0, address))
return -1;
+ if (state() == UnconnectedState)
+ bind();
qint64 sent = d->socketEngine->writeDatagram(data, size, address, port);
d->cachedSocketDescriptor = d->socketEngine->socketDescriptor();