AWS IoT Device SDK C++ v2: crt/aws-crt-cpp/include/aws/crt/io/HostResolver.h Source File

AWS IoT Device SDK C++ v2 1.14.0 AWS IoT Device SDK C++ v2

HostResolver.h
Go to the documentation of this file.
1#pragma once
6#include <aws/crt/Types.h>
7
8#include <aws/io/host_resolver.h>
9
10#include <functional>
11
12namespace Aws
13{
14 namespace Crt
15 {
16 namespace Io
17 {
18 class EventLoopGroup;
19 class HostResolver;
20
21 using HostAddress = aws_host_address;
22
28 using OnHostResolved =
29 std::function<void(HostResolver &resolver, const Vector<HostAddress> &addresses, int errorCode)>;
30
34 class AWS_CRT_CPP_API HostResolver
35 {
36 public:
37 virtual ~HostResolver();
38 virtual bool ResolveHost(const String &host, const OnHostResolved &onResolved) noexcept = 0;
39
41 virtual aws_host_resolver *GetUnderlyingHandle() noexcept = 0;
43 virtual aws_host_resolution_config *GetConfig() noexcept = 0;
44 };
45
50 class AWS_CRT_CPP_API DefaultHostResolver final : public HostResolver
51 {
52 public:
59 DefaultHostResolver(
60 EventLoopGroup &elGroup,
61 size_t maxHosts,
62 size_t maxTTL,
63 Allocator *allocator = g_allocator) noexcept;
64 ~DefaultHostResolver();
65 DefaultHostResolver(const DefaultHostResolver &) = delete;
66 DefaultHostResolver &operator=(const DefaultHostResolver &) = delete;
67 DefaultHostResolver(DefaultHostResolver &&) = delete;
68 DefaultHostResolver &operator=(DefaultHostResolver &&) = delete;
69
73 operator bool() const noexcept { return m_initialized; }
74
78 int LastError() const noexcept { return aws_last_error(); }
79
86 bool ResolveHost(const String &host, const OnHostResolved &onResolved) noexcept override;
87
89 aws_host_resolver *GetUnderlyingHandle() noexcept override { return m_resolver; }
91 aws_host_resolution_config *GetConfig() noexcept override { return &m_config; }
92
93 private:
94 aws_host_resolver *m_resolver;
95 aws_host_resolution_config m_config;
96 Allocator *m_allocator;
97 bool m_initialized;
98
99 static void s_onHostResolved(
100 struct aws_host_resolver *resolver,
101 const struct aws_string *host_name,
102 int err_code,
103 const struct aws_array_list *host_addresses,
104 void *user_data);
105 };
106 } // namespace Io
107 } // namespace Crt
108} // namespace Aws
Types.h
Aws::Crt::Io::DefaultHostResolver
Definition: HostResolver.h:51
Aws::Crt::Io::DefaultHostResolver::operator=
DefaultHostResolver & operator=(DefaultHostResolver &&)=delete
Aws::Crt::Io::DefaultHostResolver::operator=
DefaultHostResolver & operator=(const DefaultHostResolver &)=delete
Aws::Crt::Io::DefaultHostResolver::DefaultHostResolver
DefaultHostResolver(DefaultHostResolver &&)=delete
Aws::Crt::Io::DefaultHostResolver::DefaultHostResolver
DefaultHostResolver(const DefaultHostResolver &)=delete
Aws::Crt::Io::DefaultHostResolver::LastError
int LastError() const noexcept
Definition: HostResolver.h:78
Aws::Crt::Io::EventLoopGroup
Definition: EventLoopGroup.h:33
Aws::Crt::Io::HostResolver
Definition: HostResolver.h:35
Aws::Crt::Io::HostResolver::ResolveHost
virtual bool ResolveHost(const String &host, const OnHostResolved &onResolved) noexcept=0
AWS_CRT_CPP_API
#define AWS_CRT_CPP_API
Definition: Exports.h:37
Aws::Crt::Io::HostAddress
aws_host_address HostAddress
Definition: HostResolver.h:21
Aws::Crt::Io::OnHostResolved
std::function< void(HostResolver &resolver, const Vector< HostAddress > &addresses, int errorCode)> OnHostResolved
Definition: HostResolver.h:29
Aws::Crt::Allocator
aws_allocator Allocator
Definition: StlAllocator.h:17
Aws::Crt::g_allocator
AWS_CRT_CPP_API Allocator * g_allocator
Definition: Api.cpp:21
Aws::Crt::String
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > String
Definition: Types.h:47
Aws::Crt::Vector
std::vector< T, StlAllocator< T > > Vector
Definition: Types.h:55
Aws
Definition: Api.h:17