aws-crt-cpp
HostResolver.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License").
6  * You may not use this file except in compliance with the License.
7  * A copy of the License is located at
8  *
9  * http://aws.amazon.com/apache2.0
10  *
11  * or in the "license" file accompanying this file. This file is distributed
12  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16 #include <aws/crt/Types.h>
17 
18 #include <aws/io/host_resolver.h>
19 
20 #include <functional>
21 
22 namespace Aws
23 {
24  namespace Crt
25  {
26  namespace Io
27  {
28  class EventLoopGroup;
29  class HostResolver;
30 
31  using HostAddress = aws_host_address;
32 
39  std::function<void(HostResolver &resolver, const Vector<HostAddress> &addresses, int errorCode)>;
40 
42  {
43  public:
44  virtual ~HostResolver();
45  virtual bool ResolveHost(const String &host, const OnHostResolved &onResolved) noexcept = 0;
46 
48  virtual aws_host_resolver *GetUnderlyingHandle() noexcept = 0;
50  virtual aws_host_resolution_config *GetConfig() noexcept = 0;
51  };
52 
53  class DefaultHostResolver final : public HostResolver
54  {
55  public:
63  EventLoopGroup &elGroup,
64  size_t maxHosts,
65  size_t maxTTL,
66  Allocator *allocator = g_allocator) noexcept;
72 
76  operator bool() const noexcept { return m_initialized; }
80  int LastError() const noexcept { return aws_last_error(); }
81 
88  bool ResolveHost(const String &host, const OnHostResolved &onResolved) noexcept override;
89 
91  aws_host_resolver *GetUnderlyingHandle() noexcept override { return &m_resolver; }
93  aws_host_resolution_config *GetConfig() noexcept override { return &m_config; }
94 
95  private:
96  aws_host_resolver m_resolver;
97  aws_host_resolution_config m_config;
98  Allocator *m_allocator;
99  bool m_initialized;
100 
101  static void s_onHostResolved(
102  struct aws_host_resolver *resolver,
103  const struct aws_string *host_name,
104  int err_code,
105  const struct aws_array_list *host_addresses,
106  void *user_data);
107  };
108  } // namespace Io
109  } // namespace Crt
110 } // namespace Aws
Aws::Crt::Allocator
aws_allocator Allocator
Definition: StlAllocator.h:25
Aws::Crt::Vector
std::vector< T, StlAllocator< T > > Vector
Definition: Types.h:66
Aws::Crt::Io::DefaultHostResolver::DefaultHostResolver
DefaultHostResolver(DefaultHostResolver &&)=delete
Types.h
Aws::Crt::Io::DefaultHostResolver::operator=
DefaultHostResolver & operator=(DefaultHostResolver &&)=delete
Aws::Crt::Io::HostResolver
Definition: HostResolver.h:42
Aws::Crt::Io::OnHostResolved
std::function< void(HostResolver &resolver, const Vector< HostAddress > &addresses, int errorCode)> OnHostResolved
Definition: HostResolver.h:39
Aws::Crt::g_allocator
Allocator * g_allocator
Definition: Api.cpp:28
Aws::Crt::Io::EventLoopGroup
Definition: EventLoopGroup.h:43
Aws::Crt::Io::HostAddress
aws_host_address HostAddress
Definition: HostResolver.h:31
Aws::Crt::Io::DefaultHostResolver::LastError
int LastError() const noexcept
Definition: HostResolver.h:80
Aws
Definition: Api.h:25
Aws::Crt::Io::HostResolver::~HostResolver
virtual ~HostResolver()
Definition: HostResolver.cpp:27
Aws::Crt::Io::DefaultHostResolver
Definition: HostResolver.h:54
Aws::Crt::String
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > String
Definition: Types.h:58
Aws::Crt::Io::DefaultHostResolver::DefaultHostResolver
DefaultHostResolver(const DefaultHostResolver &)=delete
Aws::Crt::Io::DefaultHostResolver::operator=
DefaultHostResolver & operator=(const DefaultHostResolver &)=delete
Aws::Crt::Io::HostResolver::ResolveHost
virtual bool ResolveHost(const String &host, const OnHostResolved &onResolved) noexcept=0