TrinityCore
Loading...
Searching...
No Matches
Resolver.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "Resolver.h"
19#include <algorithm>
20
21Optional<boost::asio::ip::tcp::endpoint> Trinity::Net::Resolver::Resolve(boost::asio::ip::tcp const& protocol, std::string_view host, std::string_view service)
22{
23 boost::system::error_code ec;
24 boost::asio::ip::resolver_base::flags flagsResolver = boost::asio::ip::resolver_base::all_matching;
25 boost::asio::ip::tcp::resolver::results_type results = _impl.resolve(protocol, host, service, flagsResolver, ec);
27 if (!ec)
28 if (auto itr = results.begin(); itr != results.end())
29 result.emplace(itr->endpoint());
30
31 return result;
32}
33
34std::vector<boost::asio::ip::tcp::endpoint> Trinity::Net::Resolver::ResolveAll(std::string_view host, std::string_view service)
35{
36 boost::system::error_code ec;
37 boost::asio::ip::resolver_base::flags flagsResolver = boost::asio::ip::resolver_base::all_matching;
38 boost::asio::ip::tcp::resolver::results_type results = _impl.resolve(host, service, flagsResolver, ec);
39 std::vector<boost::asio::ip::tcp::endpoint> result;
40 if (!ec)
41 {
42 result.resize(results.size());
43 std::ranges::transform(results, result.begin(), [](boost::asio::ip::tcp::resolver::results_type::value_type const& entry) { return entry.endpoint(); });
44 }
45
46 return result;
47}
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
boost::asio::ip::basic_resolver< boost::asio::ip::tcp, Asio::IoContext::Executor > _impl
Definition Resolver.h:43
Optional< boost::asio::ip::tcp::endpoint > Resolve(boost::asio::ip::tcp const &protocol, std::string_view host, std::string_view service)
Definition Resolver.cpp:21
std::vector< boost::asio::ip::tcp::endpoint > ResolveAll(std::string_view host, std::string_view service)
Definition Resolver.cpp:34