Kea: tcp_endpoint.h Source File

| Kea 3.0.2-git

tcp_endpoint.h
Go to the documentation of this file.
1// Copyright (C) 2011-2025 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef TCP_ENDPOINT_H
8#define TCP_ENDPOINT_H 1
9
10#ifndef BOOST_ASIO_HPP
11#error "asio.hpp must be included before including this, see asiolink.h as to why"
12#endif
13
14#include <asiolink/io_endpoint.h>
15
16namespace isc {
17namespace asiolink {
18
23 class TCPEndpoint : public IOEndpoint {
24public:
28
29
34 TCPEndpoint() :
35 asio_endpoint_placeholder_(new boost::asio::ip::tcp::endpoint()),
36 asio_endpoint_(*asio_endpoint_placeholder_)
37 {}
38
43 TCPEndpoint(const IOAddress& address, const unsigned short port) :
44 asio_endpoint_placeholder_(
45 new boost::asio::ip::tcp::endpoint(boost::asio::ip::make_address(address.toText()),
46 port)),
47 asio_endpoint_(*asio_endpoint_placeholder_)
48 {}
49
56 TCPEndpoint(boost::asio::ip::tcp::endpoint& asio_endpoint) :
57 asio_endpoint_placeholder_(NULL), asio_endpoint_(asio_endpoint)
58 {}
59
66 TCPEndpoint(const boost::asio::ip::tcp::endpoint& asio_endpoint) :
67 asio_endpoint_placeholder_(new boost::asio::ip::tcp::endpoint(asio_endpoint)),
68 asio_endpoint_(*asio_endpoint_placeholder_)
69 {}
70
72 virtual ~TCPEndpoint() { delete asio_endpoint_placeholder_; }
74
75 virtual IOAddress getAddress() const {
76 return (asio_endpoint_.address());
77 }
78
79 virtual const struct sockaddr& getSockAddr() const {
80 return (*asio_endpoint_.data());
81 }
82
83 virtual uint16_t getPort() const {
84 return (asio_endpoint_.port());
85 }
86
87 virtual short getProtocol() const {
88 return (asio_endpoint_.protocol().protocol());
89 }
90
91 virtual short getFamily() const {
92 return (asio_endpoint_.protocol().family());
93 }
94
95 // This is not part of the exposed IOEndpoint API but allows
96 // direct access to the ASIO implementation of the endpoint
97 inline const boost::asio::ip::tcp::endpoint& getASIOEndpoint() const {
98 return (asio_endpoint_);
99 }
100 inline boost::asio::ip::tcp::endpoint& getASIOEndpoint() {
101 return (asio_endpoint_);
102 }
103
104private:
105 boost::asio::ip::tcp::endpoint* asio_endpoint_placeholder_;
106 boost::asio::ip::tcp::endpoint& asio_endpoint_;
107};
108
109} // namespace asiolink
110} // namespace isc
111#endif // TCP_ENDPOINT_H
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:45
isc::asiolink::TCPEndpoint::getSockAddr
virtual const struct sockaddr & getSockAddr() const
Returns the address of the endpoint in the form of sockaddr structure.
Definition tcp_endpoint.h:79
isc::asiolink::TCPEndpoint::TCPEndpoint
TCPEndpoint(const IOAddress &address, const unsigned short port)
Constructor from a pair of address and port.
Definition tcp_endpoint.h:43
isc::asiolink::TCPEndpoint::getFamily
virtual short getFamily() const
Returns the address family of the endpoint.
Definition tcp_endpoint.h:91
isc::asiolink::TCPEndpoint::TCPEndpoint
TCPEndpoint()
Default Constructor.
Definition tcp_endpoint.h:34
isc::asiolink::TCPEndpoint::getAddress
virtual IOAddress getAddress() const
Returns the address of the endpoint.
Definition tcp_endpoint.h:75
isc::asiolink::TCPEndpoint::getASIOEndpoint
boost::asio::ip::tcp::endpoint & getASIOEndpoint()
Definition tcp_endpoint.h:100
isc::asiolink::TCPEndpoint::TCPEndpoint
TCPEndpoint(const boost::asio::ip::tcp::endpoint &asio_endpoint)
Constructor from an ASIO TCP endpoint.
Definition tcp_endpoint.h:66
isc::asiolink::TCPEndpoint::getPort
virtual uint16_t getPort() const
Returns the port of the endpoint.
Definition tcp_endpoint.h:83
isc::asiolink::TCPEndpoint::getASIOEndpoint
const boost::asio::ip::tcp::endpoint & getASIOEndpoint() const
Definition tcp_endpoint.h:97
isc::asiolink::TCPEndpoint::TCPEndpoint
TCPEndpoint(boost::asio::ip::tcp::endpoint &asio_endpoint)
Constructor from an ASIO TCP endpoint.
Definition tcp_endpoint.h:56
isc::asiolink::TCPEndpoint::getProtocol
virtual short getProtocol() const
Returns the protocol number of the endpoint (TCP, UDP...).
Definition tcp_endpoint.h:87
isc::asiolink::TCPEndpoint::~TCPEndpoint
virtual ~TCPEndpoint()
The destructor.
Definition tcp_endpoint.h:72
io_endpoint.h
isc::asiolink
Definition addr_utilities.cc:170
isc::tcp
Definition mt_tcp_listener_mgr.cc:23
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148