Limit mDNS resolution retry count

This commit is contained in:
Cameron Gutman 2024-04-06 12:40:32 -05:00
parent fd2ff61a40
commit 74d452bf35

View file

@ -72,10 +72,16 @@ private slots:
void handleResolvedTimeout() void handleResolvedTimeout()
{ {
if (m_Addresses.isEmpty()) { if (m_Addresses.isEmpty()) {
if (m_Retries-- > 0) {
// Try again // Try again
qInfo() << "Resolving" << hostname() << "timed out. Retrying..."; qInfo() << "Resolving" << hostname() << "timed out. Retrying...";
resolve(); resolve();
} }
else {
qWarning() << "Giving up on resolving" << hostname() << "after repeated failures";
cleanup();
}
}
else { else {
Q_ASSERT(!m_Addresses.isEmpty()); Q_ASSERT(!m_Addresses.isEmpty());
emit resolvedHost(this, m_Addresses); emit resolvedHost(this, m_Addresses);
@ -92,7 +98,7 @@ signals:
void resolvedHost(MdnsPendingComputer*,QVector<QHostAddress>&); void resolvedHost(MdnsPendingComputer*,QVector<QHostAddress>&);
private: private:
void resolve() void cleanup()
{ {
// Delete our resolver, so we're guaranteed that nothing is referencing m_Server. // Delete our resolver, so we're guaranteed that nothing is referencing m_Server.
delete m_Resolver; delete m_Resolver;
@ -101,6 +107,12 @@ private:
// Now delete our strong reference that we held on behalf of m_Resolver. // Now delete our strong reference that we held on behalf of m_Resolver.
// The server may be destroyed after we make this call. // The server may be destroyed after we make this call.
m_Server.reset(); m_Server.reset();
}
void resolve()
{
// Clean up any existing resolver object and server references
cleanup();
// Re-acquire a strong reference if the server still exists. // Re-acquire a strong reference if the server still exists.
m_Server = m_ServerWeak.toStrongRef(); m_Server = m_ServerWeak.toStrongRef();
@ -120,6 +132,7 @@ private:
QSharedPointer<QMdnsEngine::Server> m_Server; QSharedPointer<QMdnsEngine::Server> m_Server;
QMdnsEngine::Resolver* m_Resolver; QMdnsEngine::Resolver* m_Resolver;
QVector<QHostAddress> m_Addresses; QVector<QHostAddress> m_Addresses;
int m_Retries = 10;
}; };
class ComputerPollingEntry class ComputerPollingEntry