From 9a4eb45df1796787aa149e6f128eaafa225defab Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 12 May 2023 14:26:27 -0700 Subject: QDnsLookup: simplify the processing of the runnable and reply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I3e3bfef633af4130a03afffd175e827dce2af966 Reviewed-by: Mårten Nordheim --- src/network/kernel/qdnslookup.cpp | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'src/network/kernel/qdnslookup.cpp') diff --git a/src/network/kernel/qdnslookup.cpp b/src/network/kernel/qdnslookup.cpp index 645ed31b02..4f991fd7e3 100644 --- a/src/network/kernel/qdnslookup.cpp +++ b/src/network/kernel/qdnslookup.cpp @@ -1,4 +1,5 @@ // Copyright (C) 2012 Jeremy Lainé +// 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 #include "qdnslookup.h" @@ -530,9 +531,21 @@ void QDnsLookup::lookup() Q_D(QDnsLookup); d->isFinished = false; 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); - connect(d->runnable, &QDnsLookupRunnable::finished, - this, [this](const QDnsLookupReply &reply) { d_func()->_q_lookupFinished(reply); }, + connect(d->runnable, &QDnsLookupRunnable::finished, this, l, Qt::BlockingQueuedConnection); theDnsLookupThreadPool->start(d->runnable); } @@ -1011,20 +1024,6 @@ QDnsTextRecord &QDnsTextRecord::operator=(const QDnsTextRecord &other) 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) : requestName(QUrl::toAce(d->name)), nameserver(d->nameserver), -- cgit v1.2.3