LogCabin
|
This class resolves user-friendly addresses for services into socket-level addresses. More...
#include <Address.h>
Public Types | |
typedef Core::Time::SteadyClock | Clock |
Clock used for timeouts. | |
typedef Clock::time_point | TimePoint |
Type for absolute time values used for timeouts. | |
Public Member Functions | |
Address (const std::string &str, uint16_t defaultPort) | |
Constructor. | |
Address () | |
Default constructor. | |
Address (const Address &other) | |
Copy constructor. | |
Address & | operator= (const Address &other) |
Assignment. | |
bool | isValid () const |
Return true if the sockaddr returned by getSockAddr() is valid. | |
const sockaddr * | getSockAddr () const |
Return a sockaddr that may be used to connect a socket to this Address. | |
socklen_t | getSockAddrLen () const |
Return the length in bytes of the sockaddr in getSockAddr(). | |
std::string | getResolvedString () const |
Return a string describing the sockaddr within this Address. | |
std::string | toString () const |
Return a string describing this Address. | |
void | refresh (TimePoint timeout) |
Convert (a random one of) the host(s) and port(s) to a sockaddr. | |
Private Attributes | |
std::string | originalString |
The host name(s) or numeric address(es) as passed into the constructor. | |
std::vector< std::pair < std::string, std::string > > | hosts |
A list of (host, port) pairs as parsed from originalString. | |
sockaddr_storage | storage |
Storage for the sockaddr returned by getSockAddr. | |
socklen_t | len |
The length in bytes of storage that are in use. |
This class resolves user-friendly addresses for services into socket-level addresses.
It supports DNS lookups for addressing hosts by name, and it supports multiple (alternative) addresses.
LogCabin::RPC::Address::Address | ( | const std::string & | str, |
uint16_t | defaultPort | ||
) |
Constructor.
You will usually need to call refresh() before using this class.
str | A string representation of the host and, optionally, a port number.
|
defaultPort | The port number to use if none is specified in str. |
Definition at line 35 of file Address.cc.
Default constructor.
Definition at line 71 of file Address.cc.
LogCabin::RPC::Address::Address | ( | const Address & | other | ) |
Copy constructor.
Definition at line 79 of file Address.cc.
Assignment.
Definition at line 89 of file Address.cc.
bool LogCabin::RPC::Address::isValid | ( | ) | const |
Return true if the sockaddr returned by getSockAddr() is valid.
Definition at line 99 of file Address.cc.
const sockaddr * LogCabin::RPC::Address::getSockAddr | ( | ) | const |
Return a sockaddr that may be used to connect a socket to this Address.
Definition at line 105 of file Address.cc.
socklen_t LogCabin::RPC::Address::getSockAddrLen | ( | ) | const |
Return the length in bytes of the sockaddr in getSockAddr().
This is the value you'll want to pass in to connect() or bind().
Definition at line 111 of file Address.cc.
std::string LogCabin::RPC::Address::getResolvedString | ( | ) | const |
Return a string describing the sockaddr within this Address.
This string will reflect the numeric address produced by the latest successful call to refresh(), or "Unspecified".
Definition at line 117 of file Address.cc.
std::string LogCabin::RPC::Address::toString | ( | ) | const |
Return a string describing this Address.
This will contain both the user-provided string passed into the constructor and the numeric address produced by the latest successful call to refresh(). It's the best representation to use in error messages for the user.
Definition at line 151 of file Address.cc.
void LogCabin::RPC::Address::refresh | ( | TimePoint | timeout | ) |
Convert (a random one of) the host(s) and port(s) to a sockaddr.
If the host is a name instead of numeric, this will run a DNS query and select a random result. If this query fails, any previous sockaddr will be left intact.
timeout | Not yet implemented. |
Definition at line 164 of file Address.cc.
std::string LogCabin::RPC::Address::originalString [private] |
std::vector<std::pair<std::string, std::string> > LogCabin::RPC::Address::hosts [private] |
A list of (host, port) pairs as parsed from originalString.
sockaddr_storage LogCabin::RPC::Address::storage [private] |
socklen_t LogCabin::RPC::Address::len [private] |