Add error logging to LanLinkProvider when binding the listener socket

This commit is contained in:
Simon Redman 2019-06-02 22:13:58 -06:00
parent e111e1ad51
commit 637285378d

View file

@ -30,6 +30,7 @@
#include <QHostInfo>
#include <QTcpServer>
#include <QMetaEnum>
#include <QNetworkProxy>
#include <QUdpSocket>
#include <QNetworkSession>
@ -86,9 +87,15 @@ void LanLinkProvider::onStart()
const QHostAddress bindAddress = m_testMode? QHostAddress::LocalHost : QHostAddress::Any;
bool success = m_udpSocket.bind(bindAddress, UDP_PORT, QUdpSocket::ShareAddress);
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
QString errorMessage = QLatin1String("Failed to bind UDP socket with error ");
errorMessage = errorMessage + QMetaEnum::fromType<QAbstractSocket::SocketError>().valueToKey(sockErr);
qCritical(errorMessage.toLocal8Bit().data());
}
Q_ASSERT(success);
m_tcpPort = MIN_TCP_PORT;
while (!m_server->listen(bindAddress, m_tcpPort)) {
m_tcpPort++;