Skip to content

Commit 2197cab

Browse files
committed
WIP Async writing
1 parent 8180678 commit 2197cab

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

include/openPMD/toolkit/Aws.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66

77
namespace openPMD::internal
88
{
9+
struct AwsAsyncHandler
10+
{};
11+
912
struct ExternalBlockStorageAws : ExternalBlockStorageBackend
1013
{
1114
private:
1215
Aws::S3::S3Client m_client;
1316
std::string m_bucketName;
1417
std::optional<std::string> m_endpoint;
18+
std::optional<AwsAsyncHandler> m_async;
1519

1620
public:
1721
ExternalBlockStorageAws(

src/toolkit/Aws.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,40 @@ auto ExternalBlockStorageAws::put(
7171
put_request.SetBody(input_data);
7272
put_request.SetContentLength(static_cast<long long>(len));
7373

74-
auto put_outcome = m_client.PutObject(put_request);
75-
76-
if (put_outcome.IsSuccess())
74+
if (!m_async.has_value())
7775
{
78-
std::cout << "File uploaded successfully to S3!" << std::endl;
76+
auto put_outcome = m_client.PutObject(put_request);
77+
78+
if (put_outcome.IsSuccess())
79+
{
80+
std::cout << "File uploaded successfully to S3!" << std::endl;
81+
}
82+
else
83+
{
84+
std::cerr << "Upload failed: "
85+
<< put_outcome.GetError().GetMessage() << std::endl;
86+
}
7987
}
8088
else
8189
{
82-
std::cerr << "Upload failed: " << put_outcome.GetError().GetMessage()
83-
<< std::endl;
90+
auto responseReceivedHandler =
91+
[](const Aws::S3::S3Client *,
92+
const Aws::S3::Model::PutObjectRequest &,
93+
const Aws::S3::Model::PutObjectOutcome &put_outcome,
94+
const std::shared_ptr<const Aws::Client::AsyncCallerContext> &) {
95+
if (put_outcome.IsSuccess())
96+
{
97+
std::cout << "File uploaded successfully to S3!"
98+
<< std::endl;
99+
}
100+
else
101+
{
102+
std::cerr << "Upload failed: "
103+
<< put_outcome.GetError().GetMessage()
104+
<< std::endl;
105+
}
106+
};
107+
m_client.PutObjectAsync(put_request, responseReceivedHandler);
84108
}
85109
return sanitized;
86110
}

0 commit comments

Comments
 (0)