Async  1.5.0
Public Member Functions | Public Attributes | List of all members
Async::DnsLookup Class Reference

A class for performing asynchronous DNS lookups. More...

#include <AsyncDnsLookup.h>

Inheritance diagram for Async::DnsLookup:

Public Member Functions

 DnsLookup (const std::string &label)
 Constructor. More...
 
 ~DnsLookup (void)
 Destructor. More...
 
const std::string & label (void) const
 Return the associated label. More...
 
bool resultsAreReady (void)
 Check if the DNS lookup is done or not. More...
 
std::vector< IpAddressaddresses (void)
 Return the addresses for the host in the query. More...
 

Public Attributes

sigc::signal< void, DnsLookup & > resultsReady
 A signal to indicate that the query has been completed. More...
 

Detailed Description

A class for performing asynchronous DNS lookups.

Author
Tobias Blomberg
Date
2003-04-12

Use this class to make DNS lookups. Right now it only supports looking up hostnames to find out what IP-addresses it maps to. An example usage can be seen below.

#include <iostream>
#include <AsyncDnsLookup.h>
using namespace std;
using namespace Async;
class MyClass : public sigc::trackable
{
public:
MyClass(void)
{
cout << "Starting query of www.ibm.com...\n";
dns_lookup = new DnsLookup("www.ibm.com");
dns_lookup->resultsReady.connect(mem_fun(*this, &MyClass::onResultsReady));
}
~MyClass(void)
{
delete dns_lookup;
}
void onResultsReady(DnsLookup& dns)
{
cout << "Results received:\n";
vector<IpAddress> addresses = dns.addresses();
vector<IpAddress>::iterator it;
for (it = addresses.begin(); it != addresses.end(); ++it)
{
cout << *it << endl;
}
}
private:
DnsLookup *dns_lookup;
};
int main(int argc, char **argv)
{
MyClass dns;
app.exec();
}
Examples:
AsyncDnsLookup_demo.cpp.

Definition at line 120 of file AsyncDnsLookup.h.

Constructor & Destructor Documentation

◆ DnsLookup()

Async::DnsLookup::DnsLookup ( const std::string &  label)

Constructor.

Parameters
labelThe label (hostname) to lookup

◆ ~DnsLookup()

Async::DnsLookup::~DnsLookup ( void  )

Destructor.

Member Function Documentation

◆ addresses()

std::vector<IpAddress> Async::DnsLookup::addresses ( void  )

Return the addresses for the host in the query.

Returns
Return a stl vector which contains all the addresses associated with the hostname in the query.
Precondition
The result is not available before the resultsReay signal has been emitted

Use this function to retrieve all the IP-addresses associated with the hostname in the query. If the list is empty, the query has failed.

Examples:
AsyncDnsLookup_demo.cpp.

◆ label()

const std::string& Async::DnsLookup::label ( void  ) const
inline

Return the associated label.

Returns
Returns the label associated with this DNS lookup

Definition at line 138 of file AsyncDnsLookup.h.

◆ resultsAreReady()

bool Async::DnsLookup::resultsAreReady ( void  )
inline

Check if the DNS lookup is done or not.

Returns
Returns true if results are ready or false if not

Definition at line 144 of file AsyncDnsLookup.h.

Member Data Documentation

◆ resultsReady

sigc::signal<void, DnsLookup&> Async::DnsLookup::resultsReady

A signal to indicate that the query has been completed.

Parameters
dnsA reference to the DNS object associated with the query

Definition at line 162 of file AsyncDnsLookup.h.


The documentation for this class was generated from the following file: