Skip to content

Commit a6266dc

Browse files
committed
bind out write data API
1 parent 19d1cb6 commit a6266dc

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

include/aws/crt/http/HttpConnection.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <aws/crt/Types.h>
1111
#include <aws/crt/io/Bootstrap.h>
1212
#include <aws/crt/io/SocketOptions.h>
13+
#include <aws/crt/io/Stream.h>
1314
#include <aws/crt/io/TlsOptions.h>
1415

1516
#include <functional>
@@ -118,6 +119,11 @@ namespace Aws
118119
* See `OnStreamComplete` for more info. This value can be empty.
119120
*/
120121
OnStreamComplete onStreamComplete;
122+
123+
/**
124+
* See `UseManualDataWrites` for more info. If true the write data API must be used to provide data.
125+
*/
126+
bool UseManualDataWrites = false;
121127
};
122128

123129
/**
@@ -191,6 +197,8 @@ namespace Aws
191197
std::shared_ptr<HttpStream> stream;
192198
};
193199

200+
using OnWriteDataComplete = std::function<void(std::shared_ptr<HttpStream> &stream, int errorCode)>;
201+
194202
/**
195203
* Subclass that represents an http client's view of an HttpStream.
196204
*/
@@ -216,6 +224,11 @@ namespace Aws
216224
*/
217225
bool Activate() noexcept;
218226

227+
int WriteData(
228+
std::shared_ptr<Aws::Crt::Io::InputStream> stream,
229+
const OnWriteDataComplete &onComplete,
230+
bool endStream = false) noexcept;
231+
219232
private:
220233
HttpClientStream(const std::shared_ptr<HttpClientConnection> &connection) noexcept;
221234

source/http/HttpConnection.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@
88
#include <aws/crt/http/HttpRequestResponse.h>
99
#include <aws/crt/io/Bootstrap.h>
1010

11+
namespace
12+
{
13+
struct OnWriteUserData
14+
{
15+
Aws::Crt::Http::OnWriteDataComplete callback;
16+
Aws::Crt::Http::ClientStreamCallbackData callbackData;
17+
};
18+
19+
void s_OnWriteDataComplete(struct aws_http_stream *, int error_code, void *user_data)
20+
{
21+
auto *userData = static_cast<OnWriteUserData *>(user_data);
22+
userData->callback(userData->callbackData.stream, error_code);
23+
Aws::Crt::Delete(userData, userData->callbackData.allocator);
24+
}
25+
} // namespace
26+
1127
namespace Aws
1228
{
1329
namespace Crt
@@ -202,6 +218,7 @@ namespace Aws
202218
options.on_response_headers = HttpStream::s_onIncomingHeaders;
203219
options.on_response_header_block_done = HttpStream::s_onIncomingHeaderBlockDone;
204220
options.on_complete = HttpStream::s_onStreamComplete;
221+
options.use_manual_data_writes = requestOptions.UseManualDataWrites;
205222

206223
/* Do the same ref counting trick we did with HttpClientConnection. We need to maintain a reference
207224
* internally (regardless of what the user does), until the Stream shuts down. */
@@ -361,6 +378,24 @@ namespace Aws
361378
return true;
362379
}
363380

381+
int HttpClientStream::WriteData(
382+
std::shared_ptr<Aws::Crt::Io::InputStream> stream,
383+
const OnWriteDataComplete &onComplete,
384+
bool endStream) noexcept
385+
{
386+
aws_http_stream_write_data_options options{};
387+
options.data = stream->GetUnderlyingStream();
388+
options.end_stream = endStream;
389+
options.on_complete = s_OnWriteDataComplete;
390+
391+
auto *data = Aws::Crt::New<OnWriteUserData>(m_callbackData.allocator);
392+
data->callback = onComplete;
393+
data->callbackData = m_callbackData;
394+
options.user_data = data;
395+
396+
return aws_http_stream_write_data(m_stream, &options);
397+
}
398+
364399
void HttpStream::UpdateWindow(std::size_t incrementSize) noexcept
365400
{
366401
aws_http_stream_update_window(m_stream, incrementSize);

0 commit comments

Comments
 (0)