aws-crt-cpp
HttpConnectionManager.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  */
17 
18 #include <atomic>
19 #include <condition_variable>
20 #include <future>
21 #include <mutex>
22 
23 struct aws_http_connection_manager;
24 
25 namespace Aws
26 {
27  namespace Crt
28  {
29  namespace Http
30  {
37  std::function<void(std::shared_ptr<HttpClientConnection>, int errorCode)>;
38 
43  {
44  public:
48 
51 
56 
61 
70  };
71 
76  : public std::enable_shared_from_this<HttpClientConnectionManager>
77  {
78  public:
80 
87  bool AcquireConnection(const OnClientConnectionAvailable &onClientConnectionAvailable) noexcept;
88 
95  std::future<void> InitiateShutdown() noexcept;
96 
100  static std::shared_ptr<HttpClientConnectionManager> NewClientConnectionManager(
101  const HttpClientConnectionManagerOptions &connectionManagerOptions,
102  Allocator *allocator = g_allocator) noexcept;
103 
104  private:
106  const HttpClientConnectionManagerOptions &options,
107  Allocator *allocator = g_allocator) noexcept;
108 
109  Allocator *m_allocator;
110 
111  aws_http_connection_manager *m_connectionManager;
112 
114  std::promise<void> m_shutdownPromise;
115  std::atomic<bool> m_releaseInvoked;
116 
117  static void s_onConnectionSetup(
118  aws_http_connection *connection,
119  int errorCode,
120  void *userData) noexcept;
121 
122  static void s_shutdownCompleted(void *userData) noexcept;
123 
124  friend class ManagedConnection;
125  };
126  } // namespace Http
127  } // namespace Crt
128 } // namespace Aws
Aws::Crt::Allocator
aws_allocator Allocator
Definition: StlAllocator.h:25
AWS_CRT_CPP_API
#define AWS_CRT_CPP_API
Definition: Exports.h:34
Aws::Crt::Http::HttpClientConnectionManagerOptions::EnableBlockingShutdown
bool EnableBlockingShutdown
Definition: HttpConnectionManager.h:69
Aws::Crt::Http::HttpClientConnectionManagerOptions::operator=
HttpClientConnectionManagerOptions & operator=(HttpClientConnectionManagerOptions &&rhs)=default
Aws::Crt::g_allocator
Allocator * g_allocator
Definition: Api.cpp:28
Aws::Crt::Http::HttpClientConnectionManagerOptions
Definition: HttpConnectionManager.h:43
Aws::Crt::Http::ManagedConnection
Definition: HttpConnectionManager.cpp:157
HttpConnection.h
Aws::Crt::Http::HttpClientConnectionManagerOptions::HttpClientConnectionManagerOptions
HttpClientConnectionManagerOptions(const HttpClientConnectionManagerOptions &rhs)=default
Aws
Definition: Api.h:25
Aws::Crt::Http::HttpClientConnectionManagerOptions::ConnectionOptions
HttpClientConnectionOptions ConnectionOptions
Definition: HttpConnectionManager.h:55
Aws::Crt::Http::HttpClientConnectionOptions
Definition: HttpConnection.h:286
Aws::Crt::Http::HttpClientConnectionManagerOptions::MaxConnections
size_t MaxConnections
Definition: HttpConnectionManager.h:60
Aws::Crt::Http::HttpClientConnectionManagerOptions::operator=
HttpClientConnectionManagerOptions & operator=(const HttpClientConnectionManagerOptions &rhs)=default
Aws::Crt::Http::HttpClientConnectionManager
Definition: HttpConnectionManager.h:77
Aws::Crt::Http::OnClientConnectionAvailable
std::function< void(std::shared_ptr< HttpClientConnection >, int errorCode)> OnClientConnectionAvailable
Definition: HttpConnectionManager.h:37
Aws::Crt::Http::HttpClientConnectionManagerOptions::HttpClientConnectionManagerOptions
HttpClientConnectionManagerOptions(HttpClientConnectionManagerOptions &&rhs)=default