Fixes in UPnP discovery on iOS
This commit is contained in:
parent
a4336ae1c0
commit
c1ea7a2447
@ -202,6 +202,10 @@ void NymeaDiscovery::setZeroconfDiscoveryEnabled(bool zeroconfDiscoveryEnabled)
|
|||||||
if (m_zeroconfDiscoveryEnabled != zeroconfDiscoveryEnabled) {
|
if (m_zeroconfDiscoveryEnabled != zeroconfDiscoveryEnabled) {
|
||||||
m_zeroconfDiscoveryEnabled = zeroconfDiscoveryEnabled;
|
m_zeroconfDiscoveryEnabled = zeroconfDiscoveryEnabled;
|
||||||
emit zeroconfDiscoveryEnabledChanged(m_zeroconfDiscoveryEnabled);
|
emit zeroconfDiscoveryEnabledChanged(m_zeroconfDiscoveryEnabled);
|
||||||
|
if (!m_zeroconfDiscoveryEnabled && m_zeroConf && m_zeroConf->discovering()) {
|
||||||
|
m_zeroConf->deleteLater();
|
||||||
|
m_zeroConf = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,6 +214,9 @@ void NymeaDiscovery::setBluetoothDiscoveryEnabled(bool bluetoothDiscoveryEnabled
|
|||||||
if (m_bluetoothDiscoveryEnabled != bluetoothDiscoveryEnabled) {
|
if (m_bluetoothDiscoveryEnabled != bluetoothDiscoveryEnabled) {
|
||||||
m_bluetoothDiscoveryEnabled = bluetoothDiscoveryEnabled;
|
m_bluetoothDiscoveryEnabled = bluetoothDiscoveryEnabled;
|
||||||
emit bluetoothDiscoveryEnabledChanged(m_bluetoothDiscoveryEnabled);
|
emit bluetoothDiscoveryEnabledChanged(m_bluetoothDiscoveryEnabled);
|
||||||
|
if (!m_bluetoothDiscoveryEnabled && m_bluetooth && m_bluetooth->discovering()) {
|
||||||
|
m_bluetooth->stopDiscovery();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,6 +225,9 @@ void NymeaDiscovery::setUpnpDiscoveryEnabled(bool upnpDiscoveryEnabled)
|
|||||||
if (m_upnpDiscoveryEnabled != upnpDiscoveryEnabled) {
|
if (m_upnpDiscoveryEnabled != upnpDiscoveryEnabled) {
|
||||||
m_upnpDiscoveryEnabled = upnpDiscoveryEnabled;
|
m_upnpDiscoveryEnabled = upnpDiscoveryEnabled;
|
||||||
emit upnpDiscoveryEnabledChanged(m_upnpDiscoveryEnabled);
|
emit upnpDiscoveryEnabledChanged(m_upnpDiscoveryEnabled);
|
||||||
|
if (!m_upnpDiscoveryEnabled && m_upnp && m_upnp->discovering()) {
|
||||||
|
m_upnp->stopDiscovery();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -55,6 +55,13 @@ UpnpDiscovery::UpnpDiscovery(NymeaHosts *nymeaHosts, QObject *parent) :
|
|||||||
}
|
}
|
||||||
foreach (const QNetworkAddressEntry &netAddressEntry, iface.addressEntries()) {
|
foreach (const QNetworkAddressEntry &netAddressEntry, iface.addressEntries()) {
|
||||||
if (netAddressEntry.ip().protocol() == QAbstractSocket::IPv4Protocol) {
|
if (netAddressEntry.ip().protocol() == QAbstractSocket::IPv4Protocol) {
|
||||||
|
#ifdef Q_OS_IOS
|
||||||
|
// On iOS this will fail, but it's also not of interest as we won't run app and core on the same iOS host
|
||||||
|
if (netAddressEntry.ip() == QHostAddress::LocalHost) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
QUdpSocket *socket = new QUdpSocket(this);
|
QUdpSocket *socket = new QUdpSocket(this);
|
||||||
int port = -1;
|
int port = -1;
|
||||||
for (int i = 49125; i < 65535; i++) {
|
for (int i = 49125; i < 65535; i++) {
|
||||||
@ -68,7 +75,8 @@ UpnpDiscovery::UpnpDiscovery(NymeaHosts *nymeaHosts, QObject *parent) :
|
|||||||
qCWarning(dcUPnP()) << "Discovery could not bind to interface" << netAddressEntry.ip();
|
qCWarning(dcUPnP()) << "Discovery could not bind to interface" << netAddressEntry.ip();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
qCInfo(dcUPnP()) << "Discovering on" << netAddressEntry.ip() << port;
|
bool ret = socket->joinMulticastGroup(QHostAddress("239.255.255.250"));
|
||||||
|
qCInfo(dcUPnP()) << "Discovering on" << netAddressEntry.ip() << port << ret;
|
||||||
m_sockets.append(socket);
|
m_sockets.append(socket);
|
||||||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error(QAbstractSocket::SocketError)));
|
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error(QAbstractSocket::SocketError)));
|
||||||
connect(socket, &QUdpSocket::readyRead, this, &UpnpDiscovery::readData);
|
connect(socket, &QUdpSocket::readyRead, this, &UpnpDiscovery::readData);
|
||||||
@ -116,7 +124,7 @@ void UpnpDiscovery::writeDiscoveryPacket()
|
|||||||
"MX:2\r\n"
|
"MX:2\r\n"
|
||||||
"ST: ssdp:all\r\n\r\n");
|
"ST: ssdp:all\r\n\r\n");
|
||||||
|
|
||||||
qCDebug(dcUPnP()) << "sending discovery package";
|
qCDebug(dcUPnP()) << "sending discovery packet";
|
||||||
foreach (QUdpSocket* socket, m_sockets) {
|
foreach (QUdpSocket* socket, m_sockets) {
|
||||||
qint64 ret = socket->writeDatagram(ssdpSearchMessage, QHostAddress("239.255.255.250"), 1900);
|
qint64 ret = socket->writeDatagram(ssdpSearchMessage, QHostAddress("239.255.255.250"), 1900);
|
||||||
if (ret != ssdpSearchMessage.length()) {
|
if (ret != ssdpSearchMessage.length()) {
|
||||||
@ -129,7 +137,7 @@ void UpnpDiscovery::writeDiscoveryPacket()
|
|||||||
void UpnpDiscovery::error(QAbstractSocket::SocketError error)
|
void UpnpDiscovery::error(QAbstractSocket::SocketError error)
|
||||||
{
|
{
|
||||||
QUdpSocket* socket = static_cast<QUdpSocket*>(sender());
|
QUdpSocket* socket = static_cast<QUdpSocket*>(sender());
|
||||||
qWarning() << "UPnP: Socket error:" << error << socket->errorString();
|
qWarning() << "UPnP: Socket error:" << error << socket->errorString() << socket->localAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpnpDiscovery::readData()
|
void UpnpDiscovery::readData()
|
||||||
|
|||||||
Reference in New Issue
Block a user