diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2021-03-11 13:50:56 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2021-03-18 19:53:56 -0800 |
commit | 8614491aa1a19973f2039c5c5f2e5551cc535b8c (patch) | |
tree | 3e07fe80161487b79a11e67d6dc6de1b54f1c383 /src/network/socket/qudpsocket.h | |
parent | 180f78d12680f1954f9ea3f4b00200ecfa1a853e (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/qudpsocket.h')
-rw-r--r-- | src/network/socket/qudpsocket.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/network/socket/qudpsocket.h b/src/network/socket/qudpsocket.h index e2ddba1362..d68a3d16aa 100644 --- a/src/network/socket/qudpsocket.h +++ b/src/network/socket/qudpsocket.h @@ -60,6 +60,13 @@ public: explicit QUdpSocket(QObject *parent = nullptr); virtual ~QUdpSocket(); +#if QT_VERSION < QT_VERSION_CHECK(7,0,0) && !defined(Q_CLANG_QDOC) + // ### Qt7: move into QAbstractSocket + using QAbstractSocket::bind; + bool bind(QHostAddress::SpecialAddress addr, quint16 port = 0, BindMode mode = DefaultForPlatform) + { return bind(QHostAddress(addr), port, mode); } +#endif + #ifndef QT_NO_NETWORKINTERFACE bool joinMulticastGroup(const QHostAddress &groupAddress); bool joinMulticastGroup(const QHostAddress &groupAddress, |