diff --git a/core/backends/lan/mdnslinkprovider.cpp b/core/backends/lan/mdnslinkprovider.cpp index ec16b04f4..0d934ab56 100644 --- a/core/backends/lan/mdnslinkprovider.cpp +++ b/core/backends/lan/mdnslinkprovider.cpp @@ -39,6 +39,8 @@ #include "lanpairinghandler.h" #include "kdeconnectconfig.h" +#include + MDNSLinkProvider::MDNSLinkProvider() : m_server(new Server(this)) , m_tcpPort(0) @@ -55,7 +57,46 @@ MDNSLinkProvider::MDNSLinkProvider() } -#include +MDNSLinkProvider::~MDNSLinkProvider() +{ + delete m_publisher; + delete m_serviceBrowser; +} + +void MDNSLinkProvider::onStart() +{ + m_tcpPort = MIN_TCP_PORT; + while (!m_server->listen(QHostAddress::Any, m_tcpPort)) { + m_tcpPort++; + if (m_tcpPort > MAX_TCP_PORT) { //No ports available? + qCritical(KDECONNECT_CORE) << "Error opening a port in range" << MIN_TCP_PORT << "-" << MAX_TCP_PORT; + m_tcpPort = 0; + return; + } + } + + onNetworkChange(); + qCDebug(KDECONNECT_CORE) << "MDNSLinkProvider started"; +} + +void MDNSLinkProvider::onStop() +{ + m_server->close(); + qCDebug(KDECONNECT_CORE) << "MDNSLinkProvider stopped"; +} + +void MDNSLinkProvider::onNetworkChange() +{ + initializeMDNS(); +} + +void MDNSLinkProvider::onNetworkConfigurationChanged(const QNetworkConfiguration& config) +{ + if (m_lastConfig != config && config.state() == QNetworkConfiguration::Active) { + m_lastConfig = config; + onNetworkChange(); + } +} void MDNSLinkProvider::initializeMDNS() { @@ -102,46 +143,6 @@ void MDNSLinkProvider::initializeMDNS() //Discovery } - -void MDNSLinkProvider::onNetworkConfigurationChanged(const QNetworkConfiguration& config) -{ - if (m_lastConfig != config && config.state() == QNetworkConfiguration::Active) { - m_lastConfig = config; - onNetworkChange(); - } -} - -MDNSLinkProvider::~MDNSLinkProvider() -{ -} - -void MDNSLinkProvider::onStart() -{ - m_tcpPort = MIN_TCP_PORT; - while (!m_server->listen(QHostAddress::Any, m_tcpPort)) { - m_tcpPort++; - if (m_tcpPort > MAX_TCP_PORT) { //No ports available? - qCritical(KDECONNECT_CORE) << "Error opening a port in range" << MIN_TCP_PORT << "-" << MAX_TCP_PORT; - m_tcpPort = 0; - return; - } - } - - onNetworkChange(); - qCDebug(KDECONNECT_CORE) << "MDNSLinkProvider started"; -} - -void MDNSLinkProvider::onStop() -{ - m_server->close(); - qCDebug(KDECONNECT_CORE) << "MDNSLinkProvider stopped"; -} - -void MDNSLinkProvider::onNetworkChange() -{ - initializeMDNS(); -} - void MDNSLinkProvider::connectError(QAbstractSocket::SocketError socketError) { QSslSocket* socket = qobject_cast(sender());