trantor
Non-blocking I/O cross-platform TCP network library, using C++14
Loading...
Searching...
No Matches
Resolver.h
1// Copyright 2016, Tao An. All rights reserved.
2//
3// Use of this source code is governed by a BSD-style license
4// that can be found in the License file.
5
6// Author: Tao An
7
8#pragma once
9#include <trantor/exports.h>
10#include <memory>
11#include <trantor/net/EventLoop.h>
12#include <trantor/net/InetAddress.h>
13
14namespace trantor
15{
21class TRANTOR_EXPORT Resolver
22{
23 public:
24 using Callback = std::function<void(const trantor::InetAddress&)>;
25 using ResolverResultsCallback =
26 std::function<void(const std::vector<trantor::InetAddress>&)>;
27
35 static std::shared_ptr<Resolver> newResolver(EventLoop* loop = nullptr,
36 size_t timeout = 60);
37
44 virtual void resolve(const std::string& hostname,
45 const Callback& callback) = 0;
46
53 virtual void resolve(const std::string& hostname,
54 const ResolverResultsCallback& callback) = 0;
55
56 virtual ~Resolver()
57 {
58 }
59
66 static bool isCAresUsed();
67};
68} // namespace trantor
As the name implies, this class represents an event loop that runs in a particular thread....
Definition EventLoop.h:56
Wrapper of sockaddr_in. This is an POD interface class.
Definition InetAddress.h:46
This class represents an asynchronous DNS resolver.
Definition Resolver.h:22
static bool isCAresUsed()
Check whether the c-ares library is used.
virtual void resolve(const std::string &hostname, const Callback &callback)=0
Resolve an address asynchronously.
static std::shared_ptr< Resolver > newResolver(EventLoop *loop=nullptr, size_t timeout=60)
Create a new DNS resolver.
virtual void resolve(const std::string &hostname, const ResolverResultsCallback &callback)=0
Resolve an address array asynchronously.
Definition EventLoop.h:34