QDnsLookup: simplify the processing of the runnable and reply

Change-Id: I3e3bfef633af4130a03afffd175e827dce2af966
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Thiago Macieira 2023-05-12 14:26:27 -07:00
parent 282b078fca
commit 9a4eb45df1
3 changed files with 15 additions and 19 deletions

View File

@ -1,4 +1,5 @@
// Copyright (C) 2012 Jeremy Lainé <jeremy.laine@m4x.org> // Copyright (C) 2012 Jeremy Lainé <jeremy.laine@m4x.org>
// Copyright (C) 2023 Intel Corporation.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdnslookup.h" #include "qdnslookup.h"
@ -530,9 +531,21 @@ void QDnsLookup::lookup()
Q_D(QDnsLookup); Q_D(QDnsLookup);
d->isFinished = false; d->isFinished = false;
d->reply = QDnsLookupReply(); d->reply = QDnsLookupReply();
auto l = [this](const QDnsLookupReply &reply) {
Q_D(QDnsLookup);
if (d->runnable == sender()) {
#ifdef QDNSLOOKUP_DEBUG
qDebug("DNS reply for %s: %i (%s)", qPrintable(d->name), reply.error, qPrintable(reply.errorString));
#endif
d->reply = reply;
d->runnable = nullptr;
d->isFinished = true;
emit finished();
}
};
d->runnable = new QDnsLookupRunnable(d); d->runnable = new QDnsLookupRunnable(d);
connect(d->runnable, &QDnsLookupRunnable::finished, connect(d->runnable, &QDnsLookupRunnable::finished, this, l,
this, [this](const QDnsLookupReply &reply) { d_func()->_q_lookupFinished(reply); },
Qt::BlockingQueuedConnection); Qt::BlockingQueuedConnection);
theDnsLookupThreadPool->start(d->runnable); theDnsLookupThreadPool->start(d->runnable);
} }
@ -1011,20 +1024,6 @@ QDnsTextRecord &QDnsTextRecord::operator=(const QDnsTextRecord &other)
very fast and never fails. very fast and never fails.
*/ */
void QDnsLookupPrivate::_q_lookupFinished(const QDnsLookupReply &_reply)
{
Q_Q(QDnsLookup);
if (runnable == q->sender()) {
#ifdef QDNSLOOKUP_DEBUG
qDebug("DNS reply for %s: %i (%s)", qPrintable(name), _reply.error, qPrintable(_reply.errorString));
#endif
reply = _reply;
runnable = nullptr;
isFinished = true;
emit q->finished();
}
}
inline QDnsLookupRunnable::QDnsLookupRunnable(const QDnsLookupPrivate *d) inline QDnsLookupRunnable::QDnsLookupRunnable(const QDnsLookupPrivate *d)
: requestName(QUrl::toAce(d->name)), : requestName(QUrl::toAce(d->name)),
nameserver(d->nameserver), nameserver(d->nameserver),

View File

@ -226,7 +226,6 @@ Q_SIGNALS:
private: private:
Q_DECLARE_PRIVATE(QDnsLookup) Q_DECLARE_PRIVATE(QDnsLookup)
Q_PRIVATE_SLOT(d_func(), void _q_lookupFinished(const QDnsLookupReply &reply))
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -123,8 +123,6 @@ public:
: type(QDnsLookup::A) : type(QDnsLookup::A)
, port(DnsPort) , port(DnsPort)
{ } { }
void _q_lookupFinished(const QDnsLookupReply &reply);
void nameChanged() void nameChanged()
{ {