9 #include <boost/asio/io_context.hpp> 10 #include <boost/asio/ip/address.hpp> 11 #include <boost/asio/ip/tcp.hpp> 12 #include <boost/asio/ip/udp.hpp> 23 template <
typename Protocol,
typename EndPo
intType>
26 template <
typename Protocol>
30 explicit EndPoint(boost::asio::ip::basic_endpoint<Protocol> ep)
31 : _endpoint(
std::move(ep)) {}
34 return _endpoint.address();
38 return _endpoint.port();
41 operator boost::asio::ip::basic_endpoint<Protocol>()
const {
47 boost::asio::ip::basic_endpoint<Protocol>
_endpoint;
50 template <
typename Protocol>
54 explicit EndPoint(uint16_t port) : _port(port) {}
60 operator boost::asio::ip::basic_endpoint<Protocol>()
const {
61 return {Protocol::v4(), _port};
76 boost::asio::io_context io_context;
77 boost::asio::ip::tcp::resolver resolver(io_context);
78 boost::asio::ip::tcp::resolver::query query(boost::asio::ip::tcp::v4(), address,
"", boost::asio::ip::tcp::resolver::query::canonical_name);
79 boost::asio::ip::tcp::resolver::iterator iter = resolver.resolve(query);
80 boost::asio::ip::tcp::resolver::iterator end;
83 boost::asio::ip::tcp::endpoint endpoint = *iter++;
84 return endpoint.address();
89 template <
typename Protocol>
90 static inline auto make_endpoint(boost::asio::ip::basic_endpoint<Protocol> ep) {
94 template <
typename Protocol>
96 return make_endpoint<Protocol>({
make_address(address), port});
99 template <
typename Protocol>
100 static inline auto make_endpoint(
const std::string &address, uint16_t port) {
101 return make_endpoint<Protocol>(address.c_str(), port);
104 template <
typename Protocol>
static auto make_localhost_address()
EndPoint(boost::asio::ip::basic_endpoint< Protocol > ep)
static auto make_address(const std::string &address)
This file contains definitions of common data structures used in traffic manager. ...
static auto make_endpoint(boost::asio::ip::basic_endpoint< Protocol > ep)
boost::asio::ip::basic_endpoint< Protocol > _endpoint