Kea  2.1.7-git
isc::asiolink::IOEndpoint Class Referenceabstract

The IOEndpoint class is an abstract base class to represent a communication endpoint. More...

#include <io_endpoint.h>

+ Inheritance diagram for isc::asiolink::IOEndpoint:

Public Member Functions

virtual IOAddress getAddress () const =0
 Returns the address of the endpoint. More...
 
virtual short getFamily () const =0
 Returns the address family of the endpoint. More...
 
virtual uint16_t getPort () const =0
 Returns the port of the endpoint. More...
 
virtual short getProtocol () const =0
 Returns the protocol number of the endpoint (TCP, UDP...) More...
 
virtual const struct sockaddr & getSockAddr () const =0
 Returns the address of the endpoint in the form of sockaddr structure. More...
 
bool operator!= (const IOEndpoint &other) const
 
bool operator== (const IOEndpoint &other) const
 

Static Public Member Functions

static const IOEndpointcreate (const int protocol, const IOAddress &address, const unsigned short port)
 A polymorphic factory of endpoint from address and port. More...
 

Constructors and Destructor

Note: The copy constructor and the assignment operator are intentionally defined as private, making this class non-copyable.

 IOEndpoint ()
 The default constructor. More...
 
virtual ~IOEndpoint ()
 The destructor. More...
 

Detailed Description

The IOEndpoint class is an abstract base class to represent a communication endpoint.

This class is a wrapper for the ASIO endpoint classes such as ip::tcp::endpoint and ip::udp::endpoint.

Derived class implementations are completely hidden within the implementation. User applications only get access to concrete IOEndpoint objects via the abstract interfaces.

Definition at line 38 of file io_endpoint.h.

Constructor & Destructor Documentation

◆ IOEndpoint()

isc::asiolink::IOEndpoint::IOEndpoint ( )
inlineprotected

The default constructor.

This is intentionally defined as protected as this base class should never be instantiated (except as part of a derived class).

Definition at line 53 of file io_endpoint.h.

◆ ~IOEndpoint()

virtual isc::asiolink::IOEndpoint::~IOEndpoint ( )
inlinevirtual

The destructor.

Definition at line 56 of file io_endpoint.h.

References create(), getAddress(), getFamily(), getPort(), getProtocol(), getSockAddr(), operator!=(), isc::asiolink::operator<<(), and operator==().

+ Here is the call graph for this function:

Member Function Documentation

◆ create()

const IOEndpoint * isc::asiolink::IOEndpoint::create ( const int  protocol,
const IOAddress address,
const unsigned short  port 
)
static

A polymorphic factory of endpoint from address and port.

This method creates a new instance of (a derived class of) IOEndpoint object that identifies the pair of given address and port. The appropriate derived class is chosen based on the specified transport protocol. If the protocol doesn't specify a protocol supported in this implementation, an exception of class IOError will be thrown.

Memory for the created object will be dynamically allocated. It's the caller's responsibility to delete it later. If resource allocation for the new object fails, a corresponding standard exception will be thrown.

Parameters
protocolThe transport protocol used for the endpoint. Currently, only IPPROTO_UDP and IPPROTO_TCP can be specified.
addressThe (IP) address of the endpoint.
portThe transport port number of the endpoint
Returns
A pointer to a newly created IOEndpoint object.

Definition at line 28 of file io_endpoint.cc.

References isc_throw.

Referenced by isc::dhcp::IfaceMgr::openSocketFromRemoteAddress(), and ~IOEndpoint().

◆ getAddress()

virtual IOAddress isc::asiolink::IOEndpoint::getAddress ( ) const
pure virtual

Returns the address of the endpoint.

This method returns an IOAddress object corresponding to this endpoint.

Note that the return value is a real object, not a reference or a pointer.

This is aligned with the interface of the ASIO counterpart: the address() method of ip::xxx::endpoint classes returns an ip::address object.

This also means handling the address of an endpoint using this method can be expensive. If the address information is necessary in a performance sensitive context and there's a more efficient interface for that purpose, it's probably better to avoid using this method.

This method never throws an exception.

Returns
A copy of IOAddress object corresponding to the endpoint.

Implemented in isc::asiolink::TCPEndpoint, and isc::asiolink::UDPEndpoint.

Referenced by isc::asiolink::operator<<(), operator==(), and ~IOEndpoint().

◆ getFamily()

virtual short isc::asiolink::IOEndpoint::getFamily ( ) const
pure virtual

◆ getPort()

virtual uint16_t isc::asiolink::IOEndpoint::getPort ( ) const
pure virtual

Returns the port of the endpoint.

Implemented in isc::asiolink::TCPEndpoint, and isc::asiolink::UDPEndpoint.

Referenced by isc::asiolink::operator<<(), operator==(), and ~IOEndpoint().

◆ getProtocol()

◆ getSockAddr()

virtual const struct sockaddr& isc::asiolink::IOEndpoint::getSockAddr ( ) const
pure virtual

Returns the address of the endpoint in the form of sockaddr structure.

The actual instance referenced by the returned value of this method is of per address family structure: For IPv4 (AF_INET), it's sockaddr_in; for IPv6 (AF_INET6), it's sockaddr_in6. The corresponding port and address members of the underlying structure will be set in the network byte order.

This method is "redundant" in that all information to construct the sockaddr is available via the other "get" methods. It is still defined for performance sensitive applications that need to get the address information, such as for address based access control at a high throughput. Internally it is implemented with minimum overhead such as data copy (this is another reason why this method returns a reference).

As a tradeoff, this method is more fragile; it assumes that the underlying ASIO implementation stores the address information in the form of sockaddr and it can be accessed in an efficient way. This is the case as of this writing, but if the underlying implementation changes this method may become much slower or its interface may have to be changed, too.

It is therefore discouraged for normal applications to use this method. Unless the application is very performance sensitive, it should use the other "get" method to retrieve specific information of the endpoint.

The returned reference is only valid while the corresponding IOEndpoint is valid. Once it's destructed the reference will become invalid.

Exceptions
None
Returns
Reference to a sockaddr structure corresponding to the endpoint.

Implemented in isc::asiolink::TCPEndpoint, and isc::asiolink::UDPEndpoint.

Referenced by ~IOEndpoint().

◆ operator!=()

bool isc::asiolink::IOEndpoint::operator!= ( const IOEndpoint other) const

Definition at line 50 of file io_endpoint.cc.

Referenced by ~IOEndpoint().

◆ operator==()

bool isc::asiolink::IOEndpoint::operator== ( const IOEndpoint other) const

Definition at line 42 of file io_endpoint.cc.

References getAddress(), getFamily(), getPort(), and getProtocol().

Referenced by ~IOEndpoint().

+ Here is the call graph for this function:

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