AWS IoT Device SDK C++ v2  1.34.0
AWS IoT Device SDK C++ v2
HostResolver.h
Go to the documentation of this file.
1 #pragma once
2 
6 #include <aws/crt/Types.h>
7 
8 #include <aws/io/host_resolver.h>
9 
10 #include <functional>
11 
12 namespace Aws
13 {
14  namespace Crt
15  {
16  namespace Io
17  {
18  class EventLoopGroup;
19  class HostResolver;
20 
21  using HostAddress = aws_host_address;
22 
29  std::function<void(HostResolver &resolver, const Vector<HostAddress> &addresses, int errorCode)>;
30 
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 
51  {
52  public:
62  EventLoopGroup &elGroup,
63  size_t maxHosts,
64  size_t maxTTL,
65  Allocator *allocator = ApiAllocator()) noexcept;
66 
77  DefaultHostResolver(size_t maxHosts, size_t maxTTL, Allocator *allocator = ApiAllocator()) noexcept;
78 
84 
88  operator bool() const noexcept { return m_initialized; }
89 
93  int LastError() const noexcept { return aws_last_error(); }
94 
101  bool ResolveHost(const String &host, const OnHostResolved &onResolved) noexcept override;
102 
104  aws_host_resolver *GetUnderlyingHandle() noexcept override { return m_resolver; }
106  aws_host_resolution_config *GetConfig() noexcept override { return &m_config; }
107 
108  private:
109  aws_host_resolver *m_resolver;
110  aws_host_resolution_config m_config;
111  Allocator *m_allocator;
112  bool m_initialized;
113 
114  static void s_onHostResolved(
115  struct aws_host_resolver *resolver,
116  const struct aws_string *host_name,
117  int err_code,
118  const struct aws_array_list *host_addresses,
119  void *user_data);
120  };
121  } // namespace Io
122  } // namespace Crt
123 } // namespace Aws
Aws::Crt::Io::DefaultHostResolver::LastError
int LastError() const noexcept
Definition: HostResolver.h:93
Aws::Crt::ApiAllocator
AWS_CRT_CPP_API Allocator * ApiAllocator() noexcept
Definition: Allocator.cpp:24
Aws::Crt::Io::OnHostResolved
std::function< void(HostResolver &resolver, const Vector< HostAddress > &addresses, int errorCode)> OnHostResolved
Definition: HostResolver.h:29
Aws::Crt::Io::DefaultHostResolver::operator=
DefaultHostResolver & operator=(const DefaultHostResolver &)=delete
Aws::Crt::Io::HostAddress
aws_host_address HostAddress
Definition: HostResolver.h:21
Aws::Crt::Io::HostResolver::ResolveHost
virtual bool ResolveHost(const String &host, const OnHostResolved &onResolved) noexcept=0
Types.h
Aws::Crt::Io::DefaultHostResolver
Definition: HostResolver.h:51
Aws::Crt::Io::HostResolver
Definition: HostResolver.h:35
Aws::Crt::Vector
std::vector< T, StlAllocator< T > > Vector
Definition: Types.h:53
Aws::Crt::Io::DefaultHostResolver::DefaultHostResolver
DefaultHostResolver(const DefaultHostResolver &)=delete
AWS_CRT_CPP_API
#define AWS_CRT_CPP_API
Definition: Exports.h:37
Aws
Definition: Allocator.h:11
Aws::Crt::Allocator
aws_allocator Allocator
Definition: Allocator.h:14
Aws::Crt::Io::DefaultHostResolver::operator=
DefaultHostResolver & operator=(DefaultHostResolver &&)=delete
Aws::Crt::Io::DefaultHostResolver::DefaultHostResolver
DefaultHostResolver(DefaultHostResolver &&)=delete
Aws::Crt::String
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > String
Definition: Types.h:45
Aws::Crt::Io::EventLoopGroup
Definition: EventLoopGroup.h:33