Async 1.8.0
|
A class for performing asynchronous DNS lookups. More...
#include <AsyncDnsLookup.h>
Public Types | |
using | Type = DnsResourceRecord::Type |
template<class RR > | |
using | RRList = std::vector<std::unique_ptr<RR>> |
template<class RR > | |
using | SharedRRList = std::vector<std::shared_ptr<RR>> |
Public Member Functions | |
DnsLookup (void) | |
Default Constructor. | |
DnsLookup (const std::string &label, Type type=Type::A) | |
Constructor. | |
~DnsLookup (void) | |
Destructor. | |
DnsLookup & | operator= (DnsLookup &&other) |
Move assignment operator. | |
void | setLookupParams (const std::string &label, Type type=Type::A) |
Prepare a lookup by setting up query parameters. | |
bool | lookup (const std::string &label, Type type=Type::A) |
Start a DNS lookup. | |
bool | lookup (void) |
Start a DNS lookup using previously configured parameters. | |
void | abort (void) |
Abort a pending lookup. | |
Type | type (void) const |
Return the type of lookup. | |
std::string | typeStr (void) const |
Return the type of lookup as a string. | |
const std::string & | label (void) const |
Return the associated label. | |
bool | isPending (void) const |
Check if a DNS lookup is pending. | |
bool | lookupFailed (void) const |
Check if the lookup failed. | |
bool | resultsAreReady (void) const |
Check if the DNS lookup is done or not. | |
bool | recordsValid (void) const |
Check if the cached records are valid. | |
bool | empty (void) const |
Check if the query returned any answers. | |
void | clear (void) |
Remove any cached DNS resource records. | |
void | addStaticResourceRecord (DnsResourceRecord *rr) |
Add a static resource record to the lookup result. | |
const RRList< DnsResourceRecord > & | staticResourceRecords (void) const |
Get all previously added static resource records. | |
std::vector< IpAddress > | addresses (void) |
Return the addresses for the host in the query. | |
DnsResourceRecord::List | resourceRecords (Type type=Type::ANY) const |
Return all matching resource records. | |
template<class RR > | |
void | resourceRecords (RRList< RR > &rrs) const |
Return resource records of a specific type. | |
template<class RR > | |
void | resourceRecords (SharedRRList< RR > &rrs) const |
Public Attributes | |
sigc::signal< void, DnsLookup & > | resultsReady |
A signal to indicate that the query has been completed. | |
A class for performing asynchronous DNS lookups.
Use this class to make DNS lookups. Right now it supports looking up A, PTR, CNAME and SRV records. An example usage can be seen below.
Definition at line 122 of file AsyncDnsLookup.h.
using Async::DnsLookup::RRList = std::vector<std::unique_ptr<RR>> |
Definition at line 126 of file AsyncDnsLookup.h.
using Async::DnsLookup::SharedRRList = std::vector<std::shared_ptr<RR>> |
Definition at line 127 of file AsyncDnsLookup.h.
Definition at line 125 of file AsyncDnsLookup.h.
Async::DnsLookup::DnsLookup | ( | void | ) |
Default Constructor.
Async::DnsLookup::DnsLookup | ( | const std::string & | label, |
Type | type = Type::A ) |
Constructor.
label | The label (e.g. hostname) to lookup |
type | What kind of resource record to look up |
Async::DnsLookup::~DnsLookup | ( | void | ) |
Destructor.
void Async::DnsLookup::abort | ( | void | ) |
Abort a pending lookup.
std::vector< IpAddress > Async::DnsLookup::addresses | ( | void | ) |
Return the addresses for the host in the query.
Use this function to retrieve all the IP-addresses associated with the hostname in the query. Use the lookupFailed() function to find out if the query was successful or not.
The order of the hosts in the returned vector will be randomized on each call to this function.
void Async::DnsLookup::addStaticResourceRecord | ( | DnsResourceRecord * | rr | ) |
Add a static resource record to the lookup result.
rr | The resource record to add |
Use this function to add a static resource record to the DNS lookup result. Static resource records will be added to the looked up resource records before signalling that the results are ready, just as if they have been received from the DNS system. If the lookup label is empty when a lookup is initiated, no real lookup will be performed. Only static resource records will be returned in that case.
void Async::DnsLookup::clear | ( | void | ) |
Remove any cached DNS resource records.
|
inline |
Check if the query returned any answers.
Definition at line 252 of file AsyncDnsLookup.h.
bool Async::DnsLookup::isPending | ( | void | ) | const |
Check if a DNS lookup is pending.
Referenced by Async::TcpClientBase::isIdle().
|
inline |
Return the associated label.
Definition at line 214 of file AsyncDnsLookup.h.
Referenced by Async::TcpClientBase::remoteHostName().
bool Async::DnsLookup::lookup | ( | const std::string & | label, |
Type | type = Type::A ) |
Start a DNS lookup.
label | The label (e.g. hostname) to lookup |
type | What kind of resource record to look up |
Use this function to start a DNS lookup. If a lookup is already running for the given label/type the lookup request will be ignored. If the label or type does not match a currently pending query, the pending query will be aborted. NOTE: This function may emit the resultsReady signal before returning.
bool Async::DnsLookup::lookup | ( | void | ) |
Start a DNS lookup using previously configured parameters.
Use this function to start a DNS lookup using parameters previously configured. If a lookup is already running the request will be ignored. NOTE: This function may emit the resultsReady signal before returning.
bool Async::DnsLookup::lookupFailed | ( | void | ) | const |
Check if the lookup failed.
Use this function to check if the DNS lookup completed without any errors. Even if the lookup is marked as failed it may still contain valid records.
Move assignment operator.
other | The other object to move data from |
bool Async::DnsLookup::recordsValid | ( | void | ) | const |
Check if the cached records are valid.
This function is used to check if the cache contain resource records that are still valid. A cached record become invalid when the time-to-live, TTL, expires.
|
inline |
Return resource records of a specific type.
rrs | Store RRs in this vector that match the RR type |
Use this template function to get all resource records of a specific type. E.g.
std::vector<Async::DnsResourceRecordA> rrs; dns_lookup.resourceRecords(rrs);
That code will return only the A records.
Definition at line 326 of file AsyncDnsLookup.h.
|
inline |
Definition at line 333 of file AsyncDnsLookup.h.
|
inline |
Return all matching resource records.
Use this function to return all resource records, that is of the given type, that the query resulted in. If no type is given the function will return all resource records.
Definition at line 306 of file AsyncDnsLookup.h.
References type().
bool Async::DnsLookup::resultsAreReady | ( | void | ) | const |
Check if the DNS lookup is done or not.
void Async::DnsLookup::setLookupParams | ( | const std::string & | label, |
Type | type = Type::A ) |
Prepare a lookup by setting up query parameters.
label | The label (e.g. hostname) to lookup |
type | What kind of resource record to look up |
Use this function to prepare a DNS lookup by setting up the query parameters. If the label or type does not match a currently pending query, the pending query will be aborted. To start a query, the lookup() function need to be called.
|
inline |
Get all previously added static resource records.
Definition at line 277 of file AsyncDnsLookup.h.
|
inline |
Return the type of lookup.
Definition at line 199 of file AsyncDnsLookup.h.
Referenced by resourceRecords(), and typeStr().
|
inline |
Return the type of lookup as a string.
Definition at line 205 of file AsyncDnsLookup.h.
References type(), and Async::DnsResourceRecord::typeToString().
sigc::signal<void, DnsLookup&> Async::DnsLookup::resultsReady |
A signal to indicate that the query has been completed.
dns | A reference to the DNS object associated with the query |
Definition at line 343 of file AsyncDnsLookup.h.