Set ReuseAddressHint in UDP socket

Tell Qt to bind even if something else listening to the same port.
On Unix, this is implied by ShareAddress, but not on Windows [1].

[1] https://code.qt.io/cgit/qt/qtbase.git/tree/src/network/socket/qabstractsocket.cpp?h=5.9#n1565
This commit is contained in:
Albert Vaca Cintora 2023-06-07 18:38:13 +02:00
parent dd187274f7
commit 4269ec8c2a

View file

@ -80,7 +80,7 @@ void LanLinkProvider::onStart()
{
const QHostAddress bindAddress = m_testMode ? QHostAddress::LocalHost : QHostAddress::Any;
bool success = m_udpSocket.bind(bindAddress, m_udpListenPort, QUdpSocket::ShareAddress);
bool success = m_udpSocket.bind(bindAddress, m_udpListenPort, QAbstractSocket::ShareAddress | QAbstractSocket::ReuseAddressHint);
if (!success) {
QAbstractSocket::SocketError sockErr = m_udpSocket.error();
// Refer to https://doc.qt.io/qt-5/qabstractsocket.html#SocketError-enum to decode socket error number