Kea
1.9.9-git
|
The IOEndpoint
class is an abstract base class to represent a communication endpoint.
More...
#include <io_endpoint.h>
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 IOEndpoint * | create (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... | |
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.
|
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.
|
inlinevirtual |
The destructor.
Definition at line 56 of file io_endpoint.h.
|
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.
protocol | The transport protocol used for the endpoint. Currently, only IPPROTO_UDP and IPPROTO_TCP can be specified. |
address | The (IP) address of the endpoint. |
port | The transport port number of the endpoint |
IOEndpoint
object. Definition at line 28 of file io_endpoint.cc.
References isc_throw.
|
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.
IOAddress
object corresponding to the endpoint. Implemented in isc::asiolink::TCPEndpoint, and isc::asiolink::UDPEndpoint.
Referenced by isc::asiolink::operator<<(), and operator==().
|
pure virtual |
Returns the address family of the endpoint.
Implemented in isc::asiolink::TCPEndpoint, and isc::asiolink::UDPEndpoint.
Referenced by isc::asiolink::UDPSocket< C >::open(), isc::asiolink::TLSSocket< C >::open(), isc::asiolink::TCPSocket< C >::open(), isc::asiolink::operator<<(), and operator==().
|
pure virtual |
Returns the port of the endpoint.
Implemented in isc::asiolink::TCPEndpoint, and isc::asiolink::UDPEndpoint.
Referenced by isc::asiolink::operator<<(), and operator==().
|
pure virtual |
Returns the protocol number of the endpoint (TCP, UDP...)
Implemented in isc::asiolink::TCPEndpoint, and isc::asiolink::UDPEndpoint.
Referenced by isc::asiolink::UDPSocket< C >::asyncReceive(), isc::asiolink::TLSSocket< C >::asyncReceive(), isc::asiolink::TCPSocket< C >::asyncReceive(), isc::asiolink::UDPSocket< C >::asyncSend(), isc::asiolink::TLSSocket< C >::open(), isc::asiolink::TCPSocket< C >::open(), and operator==().
|
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.
None |
sockaddr
structure corresponding to the endpoint. Implemented in isc::asiolink::TCPEndpoint, and isc::asiolink::UDPEndpoint.
bool isc::asiolink::IOEndpoint::operator!= | ( | const IOEndpoint & | other | ) | const |
Definition at line 50 of file io_endpoint.cc.
bool isc::asiolink::IOEndpoint::operator== | ( | const IOEndpoint & | other | ) | const |
Definition at line 42 of file io_endpoint.cc.
References getAddress(), getFamily(), getPort(), and getProtocol().