MongoDB C++ Driver legacy-1.0.0
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
mongo::HostAndPort Struct Reference

Name of a process on the network. More...

#include <hostandport.h>

Public Member Functions

 HostAndPort ()
 Construct an empty/invalid HostAndPort.
 
 HostAndPort (const StringData &text)
 Constructs a HostAndPort by parsing "text" of the form hostname[:portnumber] Throws an AssertionException if bad config std::string or bad port #.
 
 HostAndPort (const std::string &h, int p)
 Constructs a HostAndPort with the hostname "h" and port "p".
 
Status initialize (const StringData &s)
 (Re-)initializes this HostAndPort by parsing "s".
 
bool isLocalHost () const
 Returns true if the hostname looks localhost-y.
 
std::string toString () const
 Returns a string representation of "host:port".
 
void append (StringBuilder &ss) const
 Like toString(), above, but writes to "ss", instead.
 
bool empty () const
 Returns true if this object represents no valid HostAndPort.
 

Static Public Member Functions

static StatusWith< HostAndPort > MONGO_CLIENT_FUNC parse (const StringData &text)
 Parses "text" to produce a HostAndPort.
 

Detailed Description

Name of a process on the network.

Composed of some name component, followed optionally by a colon and a numeric port. The name might be an IPv4 or IPv6 address or a relative or fully qualified host name, or an absolute path to a unix socket.

Constructor & Destructor Documentation

◆ HostAndPort()

mongo::HostAndPort::HostAndPort ( const std::string &  h,
int  p 
)

Constructs a HostAndPort with the hostname "h" and port "p".

If "p" is -1, port() returns ServerGlobalParams::DefaultDBPort.

Member Function Documentation

◆ initialize()

Status mongo::HostAndPort::initialize ( const StringData &  s)

(Re-)initializes this HostAndPort by parsing "s".

Returns Status::OK on success. The state of this HostAndPort is unspecified after initialize() returns a non-OK status, though it is safe to assign to it or re-initialize it.

◆ isLocalHost()

bool mongo::HostAndPort::isLocalHost ( ) const

Returns true if the hostname looks localhost-y.

TODO: Make a more rigorous implementation, perhaps elsewhere in the networking library.

◆ parse()

static StatusWith< HostAndPort > MONGO_CLIENT_FUNC mongo::HostAndPort::parse ( const StringData &  text)
static

Parses "text" to produce a HostAndPort.

Returns either that or an error status describing the parse failure.


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