Fawkes API  Fawkes Development Version
fawkes::NetworkNameResolverThread Class Reference

Worker thread for NetworkNameResolver. More...

#include <>>

Inheritance diagram for fawkes::NetworkNameResolverThread:

List of all members.

Public Member Functions

 NetworkNameResolverThread (NetworkNameResolver *resolver, AvahiThread *avahi_thread=NULL)
 Constructor.
 ~NetworkNameResolverThread ()
 Destructor.
void resolve_name (const char *name)
 Enqueue name for resolution.
void resolve_address (struct sockaddr *addr, socklen_t addrlen)
 Enqueue address for resolution.
bool resolve_name_immediately (const char *name, struct sockaddr **addr, socklen_t *addr_len)
 Immediately resolve a name.
bool resolve_address_immediately (struct sockaddr *addr, socklen_t addr_len, char **name, bool *namefound)
 Immediately resolve address.
virtual void resolved_name (char *name, struct sockaddr *addr, socklen_t addrlen)
 Name has been successfully resolved.
virtual void resolved_address (struct sockaddr_in *addr, socklen_t addrlen, char *name)
 Address has been successfully resolved.
virtual void name_resolution_failed (char *name)
 Name resolution failed.
virtual void address_resolution_failed (struct sockaddr_in *addr, socklen_t addrlen)
 Address resolution failed.
virtual void loop ()
 Thread loop.

Protected Member Functions

virtual void run ()
 Stub to see name in backtrace for easier debugging.

Detailed Description

Worker thread for NetworkNameResolver.

This thread does the work for the NetworkNameResolver. It runs concurrently to the rest of the software and executes name and address lookups in a non-blocking fashion.

This class should not be used directly, but NetworkNameResolver should be used instead.

See also:
NetworkNameResolver
Author:
Tim Niemueller

Constructor & Destructor Documentation

fawkes::NetworkNameResolverThread::NetworkNameResolverThread ( NetworkNameResolver resolver,
AvahiThread avahi_thread = NULL 
)

Constructor.

Available only if Avahi is available at compile time.

Parameters:
resolvernetwork name resolver to call for results
avahi_threadAvahi thread, may be NULL in which case mDNS via Avahi is not used.

Definition at line 60 of file resolver_thread.cpp.

fawkes::NetworkNameResolverThread::~NetworkNameResolverThread ( )

Destructor.

Definition at line 82 of file resolver_thread.cpp.

References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().


Member Function Documentation

void fawkes::NetworkNameResolverThread::address_resolution_failed ( struct sockaddr_in *  addr,
socklen_t  addrlen 
) [virtual]

Address resolution failed.

The given address could not be resolved. Note that the parameter addr is given to the handler's ownership. This means especially that the handler is responsible for freeing the memory with free() after it is done with the variable.

Parameters:
addraddress whose lookup failed
addrlenlength of address

Definition at line 324 of file resolver_thread.cpp.

void fawkes::NetworkNameResolverThread::loop ( ) [virtual]

Thread loop.

This will carry out all enqueued resolution operations.

Reimplemented from fawkes::Thread.

Definition at line 334 of file resolver_thread.cpp.

References fawkes::Mutex::lock(), fawkes::Mutex::unlock(), fawkes::Thread::name(), resolve_address_immediately(), and resolve_name_immediately().

void fawkes::NetworkNameResolverThread::name_resolution_failed ( char *  name) [virtual]

Name resolution failed.

The given hostname could not be resolved. Note that the parameter name is given to the handler's ownership. This means especially that the handler is responsible for freeing the memory with free() after it is done with the variable.

Parameters:
namename whose lookup failed

Definition at line 309 of file resolver_thread.cpp.

void fawkes::NetworkNameResolverThread::resolve_address ( struct sockaddr *  addr,
socklen_t  addrlen 
)

Enqueue address for resolution.

The address is enqueued and the resolver thread woken up. The result is reported to the resolver given to the constructor.

Parameters:
addraddress to resolve, must be a struct sockaddr_in
addrlenlength of addr

Definition at line 249 of file resolver_thread.cpp.

References fawkes::Thread::wakeup(), and fawkes::Mutex::unlock().

bool fawkes::NetworkNameResolverThread::resolve_address_immediately ( struct sockaddr *  addr,
socklen_t  addr_len,
char **  name,
bool *  namefound 
)

Immediately resolve address.

This tries to lookup the address with the getnameinfo(). If that fails a textual representation of the address is created. Additionally if an Avahi thread has

Parameters:
addrpointer to a struct of type struct sockaddr_in with the address to lookup
addr_lenlength of addr in bytes
namecontains a newly allocated buffer upon successful return that you have to free after use using free().
namefoundtrue, if the name could be resolved, false if it was just transformed to a textual representation
Returns:
true if the address has been successfully resolved in which case name carries the result, false otherwise

Definition at line 187 of file resolver_thread.cpp.

Referenced by loop().

void fawkes::NetworkNameResolverThread::resolve_name ( const char *  name)

Enqueue name for resolution.

The name is enqueued and the resolver thread woken up. The result is reported to the resolver given to the constructor.

Parameters:
namename to resolve

Definition at line 228 of file resolver_thread.cpp.

References fawkes::Mutex::lock(), fawkes::Mutex::unlock(), and fawkes::Thread::wakeup().

bool fawkes::NetworkNameResolverThread::resolve_name_immediately ( const char *  name,
struct sockaddr **  addr,
socklen_t *  addr_len 
)

Immediately resolve a name.

This tries to lookup a name with the getaddrinfo() and if the name ends with .local (the host is in the .local domain) and an Avahi thread has been supplied Avahi is used to lookup the hostname as well, but this does not happen immediately because this can take some time.

Parameters:
namehost name to lookup
addrupon return and success the address result will be stored here in a newly allocated buffer which you have to free after use using free().
addr_lenupon return and success contains the length of addr in bytes
Returns:
true if the name has been successfully resolved in which case addr and addr_len carry the result, false otherwise

Definition at line 131 of file resolver_thread.cpp.

Referenced by loop().

void fawkes::NetworkNameResolverThread::resolved_address ( struct sockaddr_in *  addr,
socklen_t  addrlen,
char *  name 
) [virtual]

Address has been successfully resolved.

The ordered name lookup was successful for the given address resulting in the given name. Note that all of the parameters are given to the handler's ownership, that means especially that the handler is responsible for freeing the associated memory after it is done with the result using free() on name and addr.

Parameters:
namethe resulting hostname
addraddr record, currently always of type struct sockaddr_in (only IPv4)
addrlenlength of addr in bytes

Definition at line 294 of file resolver_thread.cpp.

void fawkes::NetworkNameResolverThread::resolved_name ( char *  name,
struct sockaddr *  addr,
socklen_t  addrlen 
) [virtual]

Name has been successfully resolved.

The ordered name lookup was successful for the given name resulting in the given addr of addrlen bytes length. Note that all of the parameters are given to the handler's ownership, that means especially that the handler is responsible for freeing the associated memory after it is done with the result using free() on name and addr.

Parameters:
namename that was resolved
addrresulting addr record, currently always of type struct sockaddr_in (only IPv4)
addrlenlength of addr in bytes

Definition at line 276 of file resolver_thread.cpp.

virtual void fawkes::NetworkNameResolverThread::run ( ) [inline, protected, virtual]

Stub to see name in backtrace for easier debugging.

See also:
Thread::run()

Reimplemented from fawkes::Thread.

Definition at line 74 of file resolver_thread.h.


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