Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changelog/feature-async-http-api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "feature",
"category": "aws-cpp-sdk-core",
"contributor": "sbiscigl",
"description": "create async http api"
}
22 changes: 22 additions & 0 deletions src/aws-cpp-sdk-core/include/aws/core/http/HttpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,28 @@ namespace Aws
false};
}

/**
* Starts an http request and returns as soon as it has been started. onResponseComplete is
* invoked with the finished response, on whichever thread the implementation completes on.
* Only implemented by http clients that can drive a request without a thread of their own.
*/
virtual Aws::Crt::Optional<Aws::Client::AWSError<Aws::Client::CoreErrors>> MakeRequestAsync(
const std::shared_ptr<HttpRequest>& request,
std::function<void(std::shared_ptr<HttpResponse>)> onResponseComplete,
std::function<void(const std::shared_ptr<Aws::Http::Connection>&)> onClientConnectionAvailable = nullptr,
Aws::Utils::RateLimits::RateLimiterInterface* readLimiter = nullptr,
Aws::Utils::RateLimits::RateLimiterInterface* writeLimiter = nullptr) const {
AWS_UNREFERENCED_PARAM(request);
AWS_UNREFERENCED_PARAM(onResponseComplete);
AWS_UNREFERENCED_PARAM(onClientConnectionAvailable);
AWS_UNREFERENCED_PARAM(readLimiter);
AWS_UNREFERENCED_PARAM(writeLimiter);
return Aws::Client::AWSError<Aws::Client::CoreErrors>{Aws::Client::CoreErrors::NOT_IMPLEMENTED,
"NotImplemented",
"async requests are not supported on this http client",
false};
}

protected:
bool m_bad;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AWS_CORE_API Connection {
virtual std::shared_ptr<Aws::Http::ClientStream> NewClientStream(
const std::shared_ptr<HttpRequest>& request,
std::function<void(int errorCode)> onStreamComplete) = 0;
virtual void Close() = 0;
};
} // namespace Http
} // namespace Aws
17 changes: 17 additions & 0 deletions src/aws-cpp-sdk-core/include/aws/core/http/crt/CRTHttpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ namespace Aws
struct ClientConfiguration;
} // namespace Client

namespace Utils
{
namespace Threading
{
class WaitGroup;
}
}

namespace Http
{
/**
Expand All @@ -52,6 +60,13 @@ namespace Aws
Aws::Utils::RateLimits::RateLimiterInterface* readLimiter,
Aws::Utils::RateLimits::RateLimiterInterface* writeLimiter) const override;

Aws::Crt::Optional<Aws::Client::AWSError<Aws::Client::CoreErrors>> MakeRequestAsync(
const std::shared_ptr<HttpRequest>& request,
std::function<void(std::shared_ptr<HttpResponse>)> onResponseComplete,
std::function<void(const std::shared_ptr<Aws::Http::Connection>&)> onClientConnectionAvailable = nullptr,
Aws::Utils::RateLimits::RateLimiterInterface* readLimiter = nullptr,
Aws::Utils::RateLimits::RateLimiterInterface* writeLimiter = nullptr) const override;

bool IsDefaultAwsHttpClient() const override { return true; }

Aws::Crt::Optional<Aws::Client::AWSError<Aws::Client::CoreErrors>> AcquireConnection(
Expand All @@ -71,6 +86,8 @@ namespace Aws
Crt::Io::ClientBootstrap& m_bootstrap;
Client::ClientConfiguration m_configuration;

std::shared_ptr<Aws::Utils::Threading::WaitGroup> m_requestLatch;

std::shared_ptr<Crt::Http::HttpClientConnectionManager> GetWithCreateConnectionManagerForRequest(const std::shared_ptr<HttpRequest>& request, const Crt::Http::HttpClientConnectionOptions& connectionOptions) const;
Crt::Http::HttpClientConnectionOptions CreateConnectionOptionsForRequest(const std::shared_ptr<HttpRequest>& request) const;
void CheckAndInitializeProxySettings(const Aws::Client::ClientConfiguration& clientConfig);
Expand Down
30 changes: 30 additions & 0 deletions src/aws-cpp-sdk-core/include/aws/core/utils/threading/WaitGroup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

#pragma once

#include <aws/core/Core_EXPORTS.h>
#include <aws/core/utils/memory/AWSMemory.h>

#include <cstddef>

namespace Aws {
namespace Utils {
namespace Threading {
class AWS_CORE_API WaitGroup {
public:
WaitGroup();
~WaitGroup();
void Add(size_t count = 1);
void Done();
void Wait();

private:
struct WaitGroupImpl;
Aws::UniquePtr<WaitGroupImpl> m_impl;
};
} // namespace Threading
} // namespace Utils
} // namespace Aws
Loading
Loading