Fixes from code review

This commit is contained in:
Aleix Pol Gonzalez 2023-08-13 19:45:15 +00:00 committed by Albert Vaca Cintora
parent 5e225a23cb
commit 1b3e8db72f
2 changed files with 8 additions and 12 deletions

View file

@ -1,4 +1,4 @@
/* mdns.h - mDNS/DNS-SD library - Public Domain - 2017 Mattias Jansson /* mdns.h - mDNS/DNS-SD library v1.4.3 - Public Domain - 2017 Mattias Jansson
* *
* This library provides a cross-platform mDNS and DNS-SD library in C. * This library provides a cross-platform mDNS and DNS-SD library in C.
* The implementation is based on RFC 6762 and RFC 6763. * The implementation is based on RFC 6762 and RFC 6763.

View file

@ -193,7 +193,7 @@ int Discoverer::listenForQueryResponses()
} }
// Start listening on all sockets // Start listening on all sockets
for (int socket : sockets) { for (int socket : std::as_const(sockets)) {
QSocketNotifier *socketNotifier = new QSocketNotifier(socket, QSocketNotifier::Read); QSocketNotifier *socketNotifier = new QSocketNotifier(socket, QSocketNotifier::Read);
QObject::connect(socketNotifier, &QSocketNotifier::activated, [this](QSocketDescriptor socket) { QObject::connect(socketNotifier, &QSocketNotifier::activated, [this](QSocketDescriptor socket) {
MdnsService discoveredService; MdnsService discoveredService;
@ -257,7 +257,7 @@ int countCommonLeadingBits(quint32 int1, quint32 int2) {
return count; return count;
} }
static QHostAddress findBestAddressMatchV4(QVector<QHostAddress> hostAddresses, const struct sockaddr *fromAddress) static QHostAddress findBestAddressMatchV4(const QVector<QHostAddress> &hostAddresses, const struct sockaddr *fromAddress)
{ {
Q_ASSERT(!hostAddresses.empty()); Q_ASSERT(!hostAddresses.empty());
if (hostAddresses.size() == 1 || fromAddress == nullptr) { if (hostAddresses.size() == 1 || fromAddress == nullptr) {
@ -291,7 +291,7 @@ static QHostAddress findBestAddressMatchV4(QVector<QHostAddress> hostAddresses,
return matchingIp; return matchingIp;
} }
static QHostAddress findBestAddressMatchV6(QVector<QHostAddress> hostAddresses, const struct sockaddr *fromAddress) static QHostAddress findBestAddressMatchV6(const QVector<QHostAddress>& hostAddresses, const struct sockaddr *fromAddress)
{ {
Q_ASSERT(!hostAddresses.empty()); Q_ASSERT(!hostAddresses.empty());
// We could do the same logic for v6 that we do for V4, but we don't care that much about IPv6 // We could do the same logic for v6 that we do for V4, but we don't care that much about IPv6
@ -595,14 +595,10 @@ void Announcer::stopAnnouncing()
void Announcer::stopListeningForQueries() void Announcer::stopListeningForQueries()
{ {
if (socketNotifier != nullptr) { delete socketNotifier;
delete socketNotifier; socketNotifier = nullptr;
socketNotifier = nullptr; delete socketNotifierV6;
} socketNotifierV6 = nullptr;
if (socketNotifierV6 != nullptr) {
delete socketNotifierV6;
socketNotifierV6 = nullptr;
}
} }
void Announcer::sendMulticastAnnounce(bool isGoodbye) void Announcer::sendMulticastAnnounce(bool isGoodbye)