Skip to content

Commit f8719c1

Browse files
committed
bind out write data API
1 parent 94a24c7 commit f8719c1

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ namespace Aws
202202
options.on_response_headers = HttpStream::s_onIncomingHeaders;
203203
options.on_response_header_block_done = HttpStream::s_onIncomingHeaderBlockDone;
204204
options.on_complete = HttpStream::s_onStreamComplete;
205+
options.use_manual_data_writes = requestOptions.UseManualDataWrites;
205206

206207
/* Do the same ref counting trick we did with HttpClientConnection. We need to maintain a reference
207208
* internally (regardless of what the user does), until the Stream shuts down. */
@@ -361,6 +362,35 @@ namespace Aws
361362
return true;
362363
}
363364

365+
struct OnWriteUserData
366+
{
367+
Aws::Crt::Http::OnWriteDataComplete callback;
368+
Aws::Crt::Http::ClientStreamCallbackData callbackData;
369+
};
370+
371+
int HttpClientStream::WriteData(
372+
std::shared_ptr<Aws::Crt::Io::InputStream> stream,
373+
const OnWriteDataComplete &onComplete,
374+
bool endStream) noexcept
375+
{
376+
aws_http_stream_write_data_options options{};
377+
options.data = stream->GetUnderlyingStream();
378+
options.end_stream = endStream;
379+
options.on_complete = +[](struct aws_http_stream *, int error_code, void *user_data)
380+
{
381+
auto *userData = static_cast<OnWriteUserData *>(user_data);
382+
userData->callback(userData->callbackData.stream, error_code);
383+
Aws::Crt::Delete(userData, userData->callbackData.allocator);
384+
};
385+
386+
auto *data = Aws::Crt::New<OnWriteUserData>(m_callbackData.allocator);
387+
data->callback = onComplete;
388+
data->callbackData = m_callbackData;
389+
options.user_data = data;
390+
391+
return aws_http_stream_write_data(m_stream, &options);
392+
}
393+
364394
void HttpStream::UpdateWindow(std::size_t incrementSize) noexcept
365395
{
366396
aws_http_stream_update_window(m_stream, incrementSize);

0 commit comments

Comments
 (0)