TrinityCore
Resolver.h
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#ifndef Resolver_h__
19#define Resolver_h__
20
21#include "IoContext.h"
22#include "Optional.h"
23#include <boost/asio/ip/tcp.hpp>
24#include <string>
25
26namespace Trinity
27{
28 namespace Asio
29 {
34 {
35 public:
36 explicit Resolver(IoContext& ioContext) : _impl(ioContext) { }
37
38 Optional<boost::asio::ip::tcp::endpoint> Resolve(boost::asio::ip::tcp const& protocol, std::string const& host, std::string const& service)
39 {
40 boost::system::error_code ec;
41 boost::asio::ip::resolver_base::flags flagsResolver = boost::asio::ip::resolver_base::all_matching;
42 boost::asio::ip::tcp::resolver::results_type results = _impl.resolve(protocol, host, service, flagsResolver, ec);
43 if (results.begin() == results.end() || ec)
44 return {};
45
46 return results.begin()->endpoint();
47 }
48
49 private:
50 boost::asio::ip::tcp::resolver _impl;
51 };
52 }
53}
54
55#endif // Resolver_h__
uint16 flags
Definition: DisableMgr.cpp:49
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
boost::asio::ip::tcp::resolver _impl
Definition: Resolver.h:50
Optional< boost::asio::ip::tcp::endpoint > Resolve(boost::asio::ip::tcp const &protocol, std::string const &host, std::string const &service)
Definition: Resolver.h:38
Resolver(IoContext &ioContext)
Definition: Resolver.h:36