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/qabstractsocket.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/qabstractsocket.h')
-rw-r--r-- | src/network/socket/qabstractsocket.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/network/socket/qabstractsocket.h b/src/network/socket/qabstractsocket.h index bf1ff7e9a2..5874ddb8e8 100644 --- a/src/network/socket/qabstractsocket.h +++ b/src/network/socket/qabstractsocket.h @@ -148,7 +148,15 @@ public: virtual bool bind(const QHostAddress &address, quint16 port = 0, BindMode mode = DefaultForPlatform); +#if QT_VERSION >= QT_VERSION_CHECK(7,0,0) || defined(Q_CLANG_QDOC) + // ### Qt7: this requires that QHostAddress stop depending on QAbstractSocket::NetworkLayerProtocol + bool bind(QHostAddress::SpecialAddress addr, quint16 port = 0, BindMode mode = DefaultForPlatform) + { return bind(QHostAddress(addr), port, mode); } + bool bind(quint16 port = 0, BindMode mode = DefaultForPlatform) + { retrurn bind(QHostAddress::Any, port, mode); } +#else bool bind(quint16 port = 0, BindMode mode = DefaultForPlatform); +#endif virtual void connectToHost(const QString &hostName, quint16 port, OpenMode mode = ReadWrite, NetworkLayerProtocol protocol = AnyIPProtocol); void connectToHost(const QHostAddress &address, quint16 port, OpenMode mode = ReadWrite); |