Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

OW32::CAsyncResolver Class Reference

An asynchronous name resolver using IO completion ports. More...

#include <AsyncResolver.h>

Inheritance diagram for OW32::CAsyncResolver:

OW32::CIoTimeoutCallback OW32::CIoTimeoutDrainCallback OW32::CFileWatchCallback List of all members.

Public Member Functions

 CAsyncResolver ()
 Construct an uninitialised resolver.
AsyncResolverError initialise (const CAsyncResolverOptions *pOptions, HANDLE hIoPort, CFileWatcher *pFileWatcher=NULL, const char *random_data=NULL)
 Initialise the resolver.
 ~CAsyncResolver ()
 Destructor for final cleanup.
AsyncResolverError terminate ()
 Shutdown the resolver.
HANDLE getIoCompletionPort ()
 Return the IO completion port in use.
void gethostbyname (CAsyncResolverHostCallback *pCallback, void *context, const char *name, int family)
 Asynchronous version of gethostbynmae.
void gethostbyaddr (CAsyncResolverHostCallback *pCallback, void *context, const void *addr, int addrlen, int family)
 Asynchronous version of gethostbyaddr.
void search (CAsyncResolverCallback *pCallback, void *context, const char *name, int dnsclass, int type)
 Asynchronous version of search.
void sendQuery (CAsyncResolverQuery *query)
 Initiate transmission of a CAsyncResolverQuery object.
AsyncResolverError getHostsDB (CAsyncResolverHostsDBPtr &hostsDB)
 Get the hosts file database, reading it in if this is the first call.
unsigned int random (unsigned int n)
 Return a random number modulo n.
const CAsyncResolverOptions * getOptions () const
 Return the options object in use by this resolver.
void OnAnswer (size_t serverIndex, bool fTCP, BYTE *abuf, size_t alen)
 Callback from CAsyncResolverServer.
void OnError (size_t serverIndex, bool fTCP, AsyncResolverError status, CAsyncResolverQuery *query)
 Callback from CAsyncResolverServer.
virtual void onTimeout (LPVOID key)
 Called by the I/O timeout manager when a timeout occurs.
virtual bool drainTimeout (CIoTimeoutCallback *pCallback, LPVOID key)
 Called by the I/O timeout manager during timeout queue draining.

Static Public Member Functions

AsyncResolverError expandName (const unsigned char *encoded, const unsigned char *abuf, size_t alen, char **s, size_t *enclen)
 Utility function to expand a name in a DNS packet.
AsyncResolverError getHostEnt (FILE *fp, struct hostent **host)
 Utility function to get a hostent structure by reading a line from a 'hosts' style file.
void freeHostEnt (struct hostent *host)
 Utility function to free a hostent structure where all fields are allocated with malloc (e.g.
const TCHAR * describeError (AsyncResolverError code)
 Utility function to provide a textual description of an error code.
AsyncResolverError readLine (FILE *fp, char **buf, size_t *bufsize)
 Utility function to read a line from a file.

Detailed Description

An asynchronous name resolver using IO completion ports.


Constructor & Destructor Documentation

OW32::CAsyncResolver::CAsyncResolver (   )  [inline]
 

Construct an uninitialised resolver.

initialise must be called before use.

OW32::CAsyncResolver::~CAsyncResolver (   ) 
 

Destructor for final cleanup.

Must call terminate() first.


Member Function Documentation

const TCHAR* OW32::CAsyncResolver::describeError (  AsyncResolverError  code  )  [static]
 

Utility function to provide a textual description of an error code.

Currently only English is supported.

Parameters:
code The error code to describe
Returns:
The error code description, never NULL.

virtual bool OW32::CAsyncResolver::drainTimeout (  CIoTimeoutCallback *  pCallback,
LPVOID  key
)  [virtual]
 

Called by the I/O timeout manager during timeout queue draining.

Not to be called directly.

Implements OW32::CIoTimeoutDrainCallback.

AsyncResolverError OW32::CAsyncResolver::expandName (  const unsigned char *  encoded,
const unsigned char *  abuf,
size_t  alen,
char **  s,
size_t *  enclen
)  [static]
 

Utility function to expand a name in a DNS packet.

Parameters:
encoded The encoded name
abuf The answer packet
alen The length of the answer packet
s Output - a NULl terminated string allocated with malloc that is the expanded name
enclen The length of the encoded name
Returns:
ARES_SUCCESS on success, otherwise an appropriate error code.

void OW32::CAsyncResolver::freeHostEnt (  struct hostent *  host  )  [static]
 

Utility function to free a hostent structure where all fields are allocated with malloc (e.g.

from getHostEnt).

Parameters:
host The structure to free

void OW32::CAsyncResolver::gethostbyaddr (  CAsyncResolverHostCallback *  pCallback,
void *  context,
const void *  addr,
int  addrlen,
int  family
) 
 

Asynchronous version of gethostbyaddr.

Parameters:
pCallback The callback to inform of errors/responses
context Arbitrary context data for the callback
addr The address to resolve
addrlen The length of the address to resolve
family Only AF_INET is currently supported
Only "struct in_addr" is supported for the address (corresponding to only AF_INET being supported).

All errors are reported via the callback

void OW32::CAsyncResolver::gethostbyname (  CAsyncResolverHostCallback *  pCallback,
void *  context,
const char *  name,
int  family
) 
 

Asynchronous version of gethostbynmae.

Parameters:
pCallback The callback to inform of errors/responses
context Arbitrary context data for the callback
name The name to resolve
family Only AF_INET is currently supported
All errors are reported via the callback

AsyncResolverError OW32::CAsyncResolver::getHostEnt (  FILE *  fp,
struct hostent **  host
)  [static]
 

Utility function to get a hostent structure by reading a line from a 'hosts' style file.

Parameters:
fp The file to read from
host Output, the hostent structure
Returns:
ARES_SUCCESS on success, otherwise an appropriate error code.

AsyncResolverError OW32::CAsyncResolver::getHostsDB (  CAsyncResolverHostsDBPtr &  hostsDB  ) 
 

Get the hosts file database, reading it in if this is the first call.

Parameters:
hostsDB The hosts database cache. Returns NULL if no change monitoring object is configured, in this case the caller is expected to parse the hosts file.
Returns:
ARES_SUCCESS if database read OK, otherwise an error code

AsyncResolverError OW32::CAsyncResolver::initialise (  const CAsyncResolverOptions *  pOptions,
HANDLE  hIoPort,
CFileWatcher *  pFileWatcher = NULL,
const char *  random_data = NULL
) 
 

Initialise the resolver.

Parameters:
pOptions An options object specifying nameservers, timeouts and the like. The options object must be initialised.
hIoPort The I/O completion port to use
pFileWatcher The file watcher to use for monitoring for hosts file changes. If none is set, the hosts file will be re-read for each query.
random_data 128 bytes of data used to initialise the random number generator, may be NULL, if so default values will be used.
Returns:
ARES_SUCCESS if successful, or an error code.

void OW32::CAsyncResolver::OnAnswer (  size_t  serverIndex,
bool  fTCP,
BYTE *  abuf,
size_t  alen
) 
 

Callback from CAsyncResolverServer.

Not for direct use.

void OW32::CAsyncResolver::OnError (  size_t  serverIndex,
bool  fTCP,
AsyncResolverError  status,
CAsyncResolverQuery *  query
) 
 

Callback from CAsyncResolverServer.

Not for direct use.

virtual void OW32::CAsyncResolver::onTimeout (  LPVOID  key  )  [virtual]
 

Called by the I/O timeout manager when a timeout occurs.

Not to be called directly.

Implements OW32::CIoTimeoutCallback.

unsigned int OW32::CAsyncResolver::random (  unsigned int  n  ) 
 

Return a random number modulo n.

If n is 0, 0 is returned.

AsyncResolverError OW32::CAsyncResolver::readLine (  FILE *  fp,
char **  buf,
size_t *  bufsize
)  [static]
 

Utility function to read a line from a file.

Parameters:
fp The file to read from
buf The buffer to read into (malloc'd, may be NULL initially)
bufsize The size of the buffer (in/out)
Returns:
ARES_SUCCESS on success, otherwise an appropriate error code.

void OW32::CAsyncResolver::search (  CAsyncResolverCallback *  pCallback,
void *  context,
const char *  name,
int  dnsclass,
int  type
) 
 

Asynchronous version of search.

Parameters:
pCallback The callback to inform of errors/responses
context Arbitrary context data for the callback
name The name to resolve
dnsclass The dns class of the query
type The dns type of the query
All errors are reported via the callback

void OW32::CAsyncResolver::sendQuery (  CAsyncResolverQuery *  query  ) 
 

Initiate transmission of a CAsyncResolverQuery object.

Parameters:
query The query to transmit
All errors are reported to the query's callback object.

AsyncResolverError OW32::CAsyncResolver::terminate (   ) 
 

Shutdown the resolver.

Must be called before disposing of the resolver object.


The documentation for this class was generated from the following file:
Generated on Sun Jun 5 01:29:20 2005 for OW32 by  doxygen 1.3.9.1