Skip to content

Commit

Permalink
Updated dependencies to latest versions. (#31)
Browse files Browse the repository at this point in the history
* Updated dependencies to latest versions.
  • Loading branch information
JonathanHenson authored Jun 19, 2019
1 parent 6e19a3f commit 8d403e2
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 317 deletions.
8 changes: 4 additions & 4 deletions aws-common-runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set(AWS_DEPS_DOWNLOAD_DIR "${AWS_DEPS_BUILD_DIR}/downloads" CACHE PATH "Dependen

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

if (UNIX AND NOT APPLE)
Expand All @@ -27,19 +27,19 @@ if (UNIX AND NOT APPLE)
endif()

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

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

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

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

set(AWS_C_CAL_URL "https://github.com/awslabs/aws-c-cal.git")
Expand Down
8 changes: 5 additions & 3 deletions include/aws/crt/http/HttpConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,10 @@ namespace Aws
/**
* Represents a connection from a Http Client to a Server.
*/
class AWS_CRT_CPP_API HttpClientConnection final : public std::enable_shared_from_this<HttpClientConnection>
class AWS_CRT_CPP_API HttpClientConnection : public std::enable_shared_from_this<HttpClientConnection>
{
public:
~HttpClientConnection();
virtual ~HttpClientConnection() = default;
HttpClientConnection(const HttpClientConnection &) = delete;
HttpClientConnection(HttpClientConnection &&) = delete;
HttpClientConnection &operator=(const HttpClientConnection &) = delete;
Expand Down Expand Up @@ -350,9 +350,11 @@ namespace Aws
*/
static bool CreateConnection(const HttpClientConnectionOptions &connectionOptions) noexcept;

private:
protected:
HttpClientConnection(aws_http_connection *m_connection, Allocator *allocator) noexcept;
aws_http_connection *m_connection;

private:
Allocator *m_allocator;
int m_lastError;

Expand Down
38 changes: 14 additions & 24 deletions include/aws/crt/http/HttpConnectionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <condition_variable>
#include <mutex>

struct aws_http_connection_manager;

namespace Aws
{
namespace Crt
Expand All @@ -26,10 +28,10 @@ namespace Aws
/**
* Invoked when a connection from the pool is available. If a connection was successfully obtained
* the connection shared_ptr can be seated into your own copy of connection. If it failed, errorCode
* will be non-zero. It is your responsibility to release the connection when you are finished with it.
* will be non-zero.
*/
using OnClientConnectionAvailable =
std::function<void(std::shared_ptr<HttpClientConnection> connection, int errorCode)>;
std::function<void(std::shared_ptr<HttpClientConnection>, int errorCode)>;

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

/**
* Releases a connection back to the pool. This will cause queued consumers to be serviced, or the
* connection will be pooled waiting on another call to AcquireConnection
*/
void ReleaseConnection(std::shared_ptr<HttpClientConnection> connection) noexcept;

int LastError() const noexcept { return m_lastError; }
explicit operator bool() const noexcept { return m_good; }

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

Vector<std::shared_ptr<HttpClientConnection>> m_connections;
List<OnClientConnectionAvailable> m_pendingConnectionRequests;
aws_http_connection_manager *m_connectionManager;

Allocator *m_allocator;
Io::ClientBootstrap *m_bootstrap;
size_t m_initialWindowSize;
Io::SocketOptions m_socketOptions;
Io::TlsConnectionOptions m_tlsConnOptions;
String m_hostName;
uint16_t m_port;
bool m_good;
int m_lastError;
size_t m_maxSize;
size_t m_outstandingVendedConnections;
size_t m_pendingConnections;
std::mutex m_connectionsLock;

void onConnectionSetup(const std::shared_ptr<HttpClientConnection> &connection, int errorCode) noexcept;
void onConnectionShutdown(HttpClientConnection &connection, int errorCode) noexcept;
bool createConnection() noexcept;
void poolOrVendConnection(std::shared_ptr<HttpClientConnection> connection, bool isRelease) noexcept;
static void s_onConnectionSetup(
aws_http_connection *connection,
int errorCode,
void *userData) noexcept;

friend class ManagedConnection;
};
} // namespace Http
} // namespace Crt
Expand Down
48 changes: 23 additions & 25 deletions source/http/HttpConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ namespace Aws
OnConnectionShutdown onConnectionShutdown;
};

class UnmanagedConnection final : public HttpClientConnection
{
public:
UnmanagedConnection(aws_http_connection *connection, Aws::Crt::Allocator *allocator)
: HttpClientConnection(connection, allocator)
{
}

~UnmanagedConnection() override
{
if (m_connection)
{
aws_http_connection_release(m_connection);
m_connection = nullptr;
}
}
};

void HttpClientConnection::s_onClientConnectionSetup(
struct aws_http_connection *connection,
int errorCode,
Expand All @@ -50,28 +68,18 @@ namespace Aws
auto *callbackData = static_cast<ConnectionCallbackData *>(user_data);
if (!errorCode)
{
Allocator *allocator = callbackData->allocator;
auto connectionObj = std::allocate_shared<UnmanagedConnection>(
Aws::Crt::StlAllocator<UnmanagedConnection>(), connection, callbackData->allocator);

/* Why aren't we using New...? Because the constructor is private and the C++ type system
* isn't the boss of me. */
auto *toSeat =
static_cast<HttpClientConnection *>(aws_mem_acquire(allocator, sizeof(HttpClientConnection)));
if (toSeat)
if (connectionObj)
{
toSeat = new (toSeat) HttpClientConnection(connection, allocator);
auto sharedPtr = std::shared_ptr<HttpClientConnection>(
toSeat, [allocator](HttpClientConnection *connection) { Delete(connection, allocator); });

callbackData->connection = sharedPtr;

callbackData->onConnectionSetup(std::move(sharedPtr), errorCode);
callbackData->connection = connectionObj;
callbackData->onConnectionSetup(std::move(connectionObj), errorCode);
return;
}

aws_http_connection_release(connection);
errorCode = aws_last_error();
callbackData->onConnectionSetup(nullptr, errorCode);
return;
}

callbackData->onConnectionSetup(nullptr, errorCode);
Expand Down Expand Up @@ -143,16 +151,6 @@ namespace Aws
{
}

HttpClientConnection::~HttpClientConnection()
{
if (m_connection)
{
/* TODO: invoke shutdown callback from here if it hasn't fired yet */
aws_http_connection_release(m_connection);
m_connection = nullptr;
}
}

struct ClientStreamCallbackData
{
Allocator *allocator;
Expand Down
Loading

0 comments on commit 8d403e2

Please sign in to comment.