QDnsLookup: make the query() function non-static
Simplifies arguments and will allow me to add stateful helper methods. Change-Id: I3e3bfef633af4130a03afffd175d6044829a96f2 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
365af87f94
commit
e1c3083dad
@ -470,7 +470,7 @@ void QDnsLookup::lookup()
|
|||||||
Q_D(QDnsLookup);
|
Q_D(QDnsLookup);
|
||||||
d->isFinished = false;
|
d->isFinished = false;
|
||||||
d->reply = QDnsLookupReply();
|
d->reply = QDnsLookupReply();
|
||||||
d->runnable = new QDnsLookupRunnable(d->type, QUrl::toAce(d->name), d->nameserver);
|
d->runnable = new QDnsLookupRunnable(d);
|
||||||
connect(d->runnable, &QDnsLookupRunnable::finished,
|
connect(d->runnable, &QDnsLookupRunnable::finished,
|
||||||
this, [this](const QDnsLookupReply &reply) { d_func()->_q_lookupFinished(reply); },
|
this, [this](const QDnsLookupReply &reply) { d_func()->_q_lookupFinished(reply); },
|
||||||
Qt::BlockingQueuedConnection);
|
Qt::BlockingQueuedConnection);
|
||||||
@ -965,6 +965,13 @@ void QDnsLookupPrivate::_q_lookupFinished(const QDnsLookupReply &_reply)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline QDnsLookupRunnable::QDnsLookupRunnable(const QDnsLookupPrivate *d)
|
||||||
|
: requestName(QUrl::toAce(d->name)),
|
||||||
|
nameserver(d->nameserver),
|
||||||
|
requestType(d->type)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void QDnsLookupRunnable::run()
|
void QDnsLookupRunnable::run()
|
||||||
{
|
{
|
||||||
QDnsLookupReply reply;
|
QDnsLookupReply reply;
|
||||||
@ -978,7 +985,7 @@ void QDnsLookupRunnable::run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Perform request.
|
// Perform request.
|
||||||
query(requestType, requestName, nameserver, &reply);
|
query(&reply);
|
||||||
|
|
||||||
// Sort results.
|
// Sort results.
|
||||||
qt_qdnsmailexchangerecord_sort(reply.mailExchangeRecords);
|
qt_qdnsmailexchangerecord_sort(reply.mailExchangeRecords);
|
||||||
|
@ -5,13 +5,9 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestName, const QHostAddress &nameserver, QDnsLookupReply *reply)
|
void QDnsLookupRunnable::query(QDnsLookupReply *reply)
|
||||||
{
|
{
|
||||||
Q_UNUSED(requestType);
|
qWarning("Not yet supported on this OS");
|
||||||
Q_UNUSED(requestName);
|
|
||||||
Q_UNUSED(nameserver);
|
|
||||||
Q_UNUSED(reply);
|
|
||||||
qWarning("Not yet supported on Android");
|
|
||||||
reply->error = QDnsLookup::ResolverError;
|
reply->error = QDnsLookup::ResolverError;
|
||||||
reply->errorString = tr("Not yet supported on this OS");
|
reply->errorString = tr("Not yet supported on this OS");
|
||||||
return;
|
return;
|
||||||
|
@ -102,21 +102,17 @@ class QDnsLookupRunnable : public QObject, public QRunnable
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QDnsLookupRunnable(QDnsLookup::Type type, const QByteArray &name, const QHostAddress &nameserver)
|
QDnsLookupRunnable(const QDnsLookupPrivate *d);
|
||||||
: requestType(type)
|
|
||||||
, requestName(name)
|
|
||||||
, nameserver(nameserver)
|
|
||||||
{ }
|
|
||||||
void run() override;
|
void run() override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void finished(const QDnsLookupReply &reply);
|
void finished(const QDnsLookupReply &reply);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void query(const int requestType, const QByteArray &requestName, const QHostAddress &nameserver, QDnsLookupReply *reply);
|
void query(QDnsLookupReply *reply);
|
||||||
QDnsLookup::Type requestType;
|
|
||||||
QByteArray requestName;
|
QByteArray requestName;
|
||||||
QHostAddress nameserver;
|
QHostAddress nameserver;
|
||||||
|
QDnsLookup::Type requestType;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QDnsLookupThreadPool : public QThreadPool
|
class QDnsLookupThreadPool : public QThreadPool
|
||||||
|
@ -100,7 +100,7 @@ static const char *applyNameServer(res_state state, const QHostAddress &nameserv
|
|||||||
}
|
}
|
||||||
#endif // !QT_CONFIG(res_setservers)
|
#endif // !QT_CONFIG(res_setservers)
|
||||||
|
|
||||||
void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestName, const QHostAddress &nameserver, QDnsLookupReply *reply)
|
void QDnsLookupRunnable::query(QDnsLookupReply *reply)
|
||||||
{
|
{
|
||||||
// Initialize state.
|
// Initialize state.
|
||||||
std::remove_pointer_t<res_state> state = {};
|
std::remove_pointer_t<res_state> state = {};
|
||||||
|
@ -51,7 +51,7 @@ DNS_STATUS WINAPI DnsQueryEx(PDNS_QUERY_REQUEST pQueryRequest,
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestName, const QHostAddress &nameserver, QDnsLookupReply *reply)
|
void QDnsLookupRunnable::query(QDnsLookupReply *reply)
|
||||||
{
|
{
|
||||||
// Perform DNS query.
|
// Perform DNS query.
|
||||||
const QString requestNameUtf16 = QString::fromUtf8(requestName.data(), requestName.size());
|
const QString requestNameUtf16 = QString::fromUtf8(requestName.data(), requestName.size());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user