fawkes::NetworkNameResolverThread Class Reference
[Fawkes Network Communication]
Worker thread for NetworkNameResolver.
More...
#include <netcomm/utils/resolver_thread.h>

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
Definition at line 50 of file resolver_thread.h.
Constructor & Destructor Documentation
| fawkes::NetworkNameResolverThread::NetworkNameResolverThread | ( | NetworkNameResolver * | resolver, | |
| AvahiThread * | avahi_thread = NULL | |||
| ) |
Constructor.
Available only if Avahi is available at compile time.
- Parameters:
-
resolver network name resolver to call for results avahi_thread Avahi 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:
-
addr address whose lookup failed addrlen length 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::Thread::name(), resolve_address_immediately(), resolve_name_immediately(), and fawkes::Mutex::unlock().
| 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:
-
name name 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:
-
addr address to resolve, must be a struct sockaddr_in addrlen length of addr
Definition at line 249 of file resolver_thread.cpp.
References fawkes::Mutex::lock(), fawkes::Mutex::unlock(), and fawkes::Thread::wakeup().
Referenced by fawkes::NetworkNameResolver::resolve_address().
| 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:
-
addr pointer to a struct of type struct sockaddr_in with the address to lookup addr_len length of addr in bytes name contains a newly allocated buffer upon successful return that you have to free after use using free(). namefound true, 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:
-
name name to resolve
Definition at line 228 of file resolver_thread.cpp.
References fawkes::Mutex::lock(), fawkes::Mutex::unlock(), and fawkes::Thread::wakeup().
Referenced by fawkes::NetworkNameResolver::resolve_name().
| 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:
-
name host name to lookup addr upon 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_len upon 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(), and fawkes::NetworkNameResolver::resolve_name_blocking().
| 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:
-
name the resulting hostname addr addr record, currently always of type struct sockaddr_in (only IPv4) addrlen length 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:
-
name name that was resolved addr resulting addr record, currently always of type struct sockaddr_in (only IPv4) addrlen length 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:
- src/libs/netcomm/utils/resolver_thread.h
- src/libs/netcomm/utils/resolver_thread.cpp

