summaryrefslogtreecommitdiffstats
path: root/src/network/socket/qabstractsocket.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2021-03-11 13:50:56 -0800
committerThiago Macieira <thiago.macieira@intel.com>2021-03-18 19:53:56 -0800
commit8614491aa1a19973f2039c5c5f2e5551cc535b8c (patch)
tree3e07fe80161487b79a11e67d6dc6de1b54f1c383 /src/network/socket/qabstractsocket.cpp
parent180f78d12680f1954f9ea3f4b00200ecfa1a853e (diff)
QAbstractSocket: fake a bind(QHostAddress::SpecialAddress)
Because this is misleading: socket.bind(QHostAddress::AnyIPv4); The conversion of enum to int has preference over the construction of QHostAddress from enum, so that ends up calling bind(6), which attempts to bind to privileged port 6 and just returns with error. Meanwhile, socket.bind(QHostAddress::AnyIPv4, 0); does construct the QHostAddress because that is preferred to converting the int to the BindMode enum. Ideally we'd simply add the overload to QAbstractSocket but we can't do that because QHostAddress depends on QAbstractSocket. So I've added a Qt7 task to invert that dependency. Change-Id: I26b8286f61534f88b649fffd166b683266597796 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/network/socket/qabstractsocket.cpp')
-rw-r--r--src/network/socket/qabstractsocket.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp
index 31847c0142..16819404f4 100644
--- a/src/network/socket/qabstractsocket.cpp
+++ b/src/network/socket/qabstractsocket.cpp
@@ -1604,6 +1604,19 @@ bool QAbstractSocketPrivate::bind(const QHostAddress &address, quint16 port, QAb
}
/*!
+ \fn bool QAbstractSocket::bind(QHostAddress::SpecialAddress addr, quint16 port, BindMode mode)
+ \since 6.2
+ \overload
+
+ Binds to the special address \a addr on port \a port, using the BindMode \a
+ mode.
+
+ By default, the socket is bound using the DefaultForPlatform BindMode.
+ If a port is not specified, a random port is chosen.
+*/
+
+/*!
+ \fn bool QAbstractSocket::bind(quint16 port, BindMode mode)
\since 5.0
\overload
@@ -1612,10 +1625,12 @@ bool QAbstractSocketPrivate::bind(const QHostAddress &address, quint16 port, QAb
By default, the socket is bound using the DefaultForPlatform BindMode.
If a port is not specified, a random port is chosen.
*/
+#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
bool QAbstractSocket::bind(quint16 port, BindMode mode)
{
return bind(QHostAddress::Any, port, mode);
}
+#endif
/*!
Returns \c true if the socket is valid and ready for use; otherwise