Skip to content

Commit 8d403e2

Browse files
Updated dependencies to latest versions. (aws#31)
* Updated dependencies to latest versions.
1 parent 6e19a3f commit 8d403e2

File tree

6 files changed

+130
-317
lines changed

6 files changed

+130
-317
lines changed

aws-common-runtime/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set(AWS_DEPS_DOWNLOAD_DIR "${AWS_DEPS_BUILD_DIR}/downloads" CACHE PATH "Dependen
1717

1818
message("install dir ${AWS_DEPS_INSTALL_DIR}")
1919
set(AWS_C_COMMON_URL "https://github.com/awslabs/aws-c-common.git")
20-
set(AWS_C_COMMON_SHA "v0.3.11")
20+
set(AWS_C_COMMON_SHA "v0.3.14")
2121
include(BuildAwsCCommon)
2222

2323
if (UNIX AND NOT APPLE)
@@ -27,19 +27,19 @@ if (UNIX AND NOT APPLE)
2727
endif()
2828

2929
set(AWS_C_IO_URL "https://github.com/awslabs/aws-c-io.git")
30-
set(AWS_C_IO_SHA "v0.3.9")
30+
set(AWS_C_IO_SHA "v0.3.14")
3131
include(BuildAwsCIO)
3232

3333
set(AWS_C_COMPRESSION_URL "https://github.com/awslabs/aws-c-compression.git")
3434
set(AWS_C_COMPRESSION_SHA "v0.2.1")
3535
include(BuildAwsCCompression)
3636

3737
set(AWS_C_HTTP_URL "https://github.com/awslabs/aws-c-http.git")
38-
set(AWS_C_HTTP_SHA "v0.2.16")
38+
set(AWS_C_HTTP_SHA "v0.2.18")
3939
include(BuildAwsCHttp)
4040

4141
set(AWS_C_MQTT_URL "https://github.com/awslabs/aws-c-mqtt.git")
42-
set(AWS_C_MQTT_SHA "v0.3.7")
42+
set(AWS_C_MQTT_SHA "v0.3.8")
4343
include(BuildAwsCMqtt)
4444

4545
set(AWS_C_CAL_URL "https://github.com/awslabs/aws-c-cal.git")

include/aws/crt/http/HttpConnection.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,10 @@ namespace Aws
303303
/**
304304
* Represents a connection from a Http Client to a Server.
305305
*/
306-
class AWS_CRT_CPP_API HttpClientConnection final : public std::enable_shared_from_this<HttpClientConnection>
306+
class AWS_CRT_CPP_API HttpClientConnection : public std::enable_shared_from_this<HttpClientConnection>
307307
{
308308
public:
309-
~HttpClientConnection();
309+
virtual ~HttpClientConnection() = default;
310310
HttpClientConnection(const HttpClientConnection &) = delete;
311311
HttpClientConnection(HttpClientConnection &&) = delete;
312312
HttpClientConnection &operator=(const HttpClientConnection &) = delete;
@@ -350,9 +350,11 @@ namespace Aws
350350
*/
351351
static bool CreateConnection(const HttpClientConnectionOptions &connectionOptions) noexcept;
352352

353-
private:
353+
protected:
354354
HttpClientConnection(aws_http_connection *m_connection, Allocator *allocator) noexcept;
355355
aws_http_connection *m_connection;
356+
357+
private:
356358
Allocator *m_allocator;
357359
int m_lastError;
358360

include/aws/crt/http/HttpConnectionManager.h

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <condition_variable>
1818
#include <mutex>
1919

20+
struct aws_http_connection_manager;
21+
2022
namespace Aws
2123
{
2224
namespace Crt
@@ -26,10 +28,10 @@ namespace Aws
2628
/**
2729
* Invoked when a connection from the pool is available. If a connection was successfully obtained
2830
* the connection shared_ptr can be seated into your own copy of connection. If it failed, errorCode
29-
* will be non-zero. It is your responsibility to release the connection when you are finished with it.
31+
* will be non-zero.
3032
*/
3133
using OnClientConnectionAvailable =
32-
std::function<void(std::shared_ptr<HttpClientConnection> connection, int errorCode)>;
34+
std::function<void(std::shared_ptr<HttpClientConnection>, int errorCode)>;
3335

3436
struct HttpClientConnectionManagerOptions
3537
{
@@ -54,17 +56,11 @@ namespace Aws
5456
/**
5557
* Acquires a connection from the pool. onClientConnectionAvailable will be invoked upon an available
5658
* connection. Returns true if the connection request was successfully pooled, returns false if it
57-
* failed. On failure, onClientConnectionAvailable will not be invoked. After receiving a connection,
58-
* you must invoke ReleaseConnection().
59+
* failed. On failure, onClientConnectionAvailable will not be invoked. After receiving a connection, it
60+
* will automatically be cleaned up when your last reference to the shared_ptr is released.
5961
*/
6062
bool AcquireConnection(const OnClientConnectionAvailable &onClientConnectionAvailable) noexcept;
6163

62-
/**
63-
* Releases a connection back to the pool. This will cause queued consumers to be serviced, or the
64-
* connection will be pooled waiting on another call to AcquireConnection
65-
*/
66-
void ReleaseConnection(std::shared_ptr<HttpClientConnection> connection) noexcept;
67-
6864
int LastError() const noexcept { return m_lastError; }
6965
explicit operator bool() const noexcept { return m_good; }
7066

@@ -77,26 +73,20 @@ namespace Aws
7773
const HttpClientConnectionManagerOptions &connectionManagerOptions,
7874
Allocator *allocator = DefaultAllocator()) noexcept;
7975

80-
Vector<std::shared_ptr<HttpClientConnection>> m_connections;
81-
List<OnClientConnectionAvailable> m_pendingConnectionRequests;
76+
aws_http_connection_manager *m_connectionManager;
77+
8278
Allocator *m_allocator;
8379
Io::ClientBootstrap *m_bootstrap;
84-
size_t m_initialWindowSize;
85-
Io::SocketOptions m_socketOptions;
8680
Io::TlsConnectionOptions m_tlsConnOptions;
87-
String m_hostName;
88-
uint16_t m_port;
8981
bool m_good;
9082
int m_lastError;
91-
size_t m_maxSize;
92-
size_t m_outstandingVendedConnections;
93-
size_t m_pendingConnections;
94-
std::mutex m_connectionsLock;
9583

96-
void onConnectionSetup(const std::shared_ptr<HttpClientConnection> &connection, int errorCode) noexcept;
97-
void onConnectionShutdown(HttpClientConnection &connection, int errorCode) noexcept;
98-
bool createConnection() noexcept;
99-
void poolOrVendConnection(std::shared_ptr<HttpClientConnection> connection, bool isRelease) noexcept;
84+
static void s_onConnectionSetup(
85+
aws_http_connection *connection,
86+
int errorCode,
87+
void *userData) noexcept;
88+
89+
friend class ManagedConnection;
10090
};
10191
} // namespace Http
10292
} // namespace Crt

source/http/HttpConnection.cpp

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ namespace Aws
3939
OnConnectionShutdown onConnectionShutdown;
4040
};
4141

42+
class UnmanagedConnection final : public HttpClientConnection
43+
{
44+
public:
45+
UnmanagedConnection(aws_http_connection *connection, Aws::Crt::Allocator *allocator)
46+
: HttpClientConnection(connection, allocator)
47+
{
48+
}
49+
50+
~UnmanagedConnection() override
51+
{
52+
if (m_connection)
53+
{
54+
aws_http_connection_release(m_connection);
55+
m_connection = nullptr;
56+
}
57+
}
58+
};
59+
4260
void HttpClientConnection::s_onClientConnectionSetup(
4361
struct aws_http_connection *connection,
4462
int errorCode,
@@ -50,28 +68,18 @@ namespace Aws
5068
auto *callbackData = static_cast<ConnectionCallbackData *>(user_data);
5169
if (!errorCode)
5270
{
53-
Allocator *allocator = callbackData->allocator;
71+
auto connectionObj = std::allocate_shared<UnmanagedConnection>(
72+
Aws::Crt::StlAllocator<UnmanagedConnection>(), connection, callbackData->allocator);
5473

55-
/* Why aren't we using New...? Because the constructor is private and the C++ type system
56-
* isn't the boss of me. */
57-
auto *toSeat =
58-
static_cast<HttpClientConnection *>(aws_mem_acquire(allocator, sizeof(HttpClientConnection)));
59-
if (toSeat)
74+
if (connectionObj)
6075
{
61-
toSeat = new (toSeat) HttpClientConnection(connection, allocator);
62-
auto sharedPtr = std::shared_ptr<HttpClientConnection>(
63-
toSeat, [allocator](HttpClientConnection *connection) { Delete(connection, allocator); });
64-
65-
callbackData->connection = sharedPtr;
66-
67-
callbackData->onConnectionSetup(std::move(sharedPtr), errorCode);
76+
callbackData->connection = connectionObj;
77+
callbackData->onConnectionSetup(std::move(connectionObj), errorCode);
6878
return;
6979
}
7080

7181
aws_http_connection_release(connection);
7282
errorCode = aws_last_error();
73-
callbackData->onConnectionSetup(nullptr, errorCode);
74-
return;
7583
}
7684

7785
callbackData->onConnectionSetup(nullptr, errorCode);
@@ -143,16 +151,6 @@ namespace Aws
143151
{
144152
}
145153

146-
HttpClientConnection::~HttpClientConnection()
147-
{
148-
if (m_connection)
149-
{
150-
/* TODO: invoke shutdown callback from here if it hasn't fired yet */
151-
aws_http_connection_release(m_connection);
152-
m_connection = nullptr;
153-
}
154-
}
155-
156154
struct ClientStreamCallbackData
157155
{
158156
Allocator *allocator;

0 commit comments

Comments
 (0)