aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream
diff options
context:
space:
mode:
authordakovalkov <dakovalkov@yandex-team.com>2023-12-03 13:33:55 +0300
committerdakovalkov <dakovalkov@yandex-team.com>2023-12-03 14:04:39 +0300
commit2a718325637e5302334b6d0a6430f63168f8dbb3 (patch)
tree64be81080b7df9ec1d86d053a0c394ae53fcf1fe /contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream
parente0d94a470142d95c3007e9c5d80380994940664a (diff)
downloadydb-2a718325637e5302334b6d0a6430f63168f8dbb3.tar.gz
Update contrib/libs/aws-sdk-cpp to 1.11.37
Diffstat (limited to 'contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream')
-rw-r--r--contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/ResponseStream.cpp63
-rw-r--r--contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/SimpleStreamBuf.cpp10
2 files changed, 71 insertions, 2 deletions
diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/ResponseStream.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/ResponseStream.cpp
index 6d1f90ed12..26c92eaafd 100644
--- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/ResponseStream.cpp
+++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/ResponseStream.cpp
@@ -5,6 +5,7 @@
#include <aws/core/utils/stream/ResponseStream.h>
#include <aws/core/utils/memory/stl/AWSStringStream.h>
+#include <aws/core/utils/logging/LogMacros.h>
#if defined(_GLIBCXX_FULLY_DYNAMIC_STRING) && _GLIBCXX_FULLY_DYNAMIC_STRING == 0 && defined(__ANDROID__)
#include <aws/core/utils/stream/SimpleStreamBuf.h>
@@ -15,6 +16,8 @@ using DefaultStreamBufType = Aws::StringBuf;
using namespace Aws::Utils::Stream;
+const int ResponseStream::ResponseStream::xindex = std::ios_base::xalloc();
+
ResponseStream::ResponseStream(void) :
m_underlyingStream(nullptr)
{
@@ -23,16 +26,20 @@ ResponseStream::ResponseStream(void) :
ResponseStream::ResponseStream(Aws::IOStream* underlyingStreamToManage) :
m_underlyingStream(underlyingStreamToManage)
{
+ RegisterStream();
}
ResponseStream::ResponseStream(const Aws::IOStreamFactory& factory) :
m_underlyingStream(factory())
{
+ RegisterStream();
}
ResponseStream::ResponseStream(ResponseStream&& toMove) : m_underlyingStream(toMove.m_underlyingStream)
{
+ toMove.DeregisterStream();
toMove.m_underlyingStream = nullptr;
+ RegisterStream();
}
ResponseStream& ResponseStream::operator=(ResponseStream&& toMove)
@@ -43,12 +50,26 @@ ResponseStream& ResponseStream::operator=(ResponseStream&& toMove)
}
ReleaseStream();
+ toMove.DeregisterStream();
m_underlyingStream = toMove.m_underlyingStream;
toMove.m_underlyingStream = nullptr;
+ RegisterStream();
return *this;
}
+Aws::IOStream& ResponseStream::GetUnderlyingStream() const
+{
+ if (!m_underlyingStream)
+ {
+ assert(m_underlyingStream);
+ AWS_LOGSTREAM_FATAL("ResponseStream", "Unexpected nullptr m_underlyingStream");
+ static DefaultUnderlyingStream fallbackStream; // we are already in UB, let's just not crash existing apps
+ return fallbackStream;
+ }
+ return *m_underlyingStream;
+}
+
ResponseStream::~ResponseStream()
{
ReleaseStream();
@@ -58,13 +79,53 @@ void ResponseStream::ReleaseStream()
{
if (m_underlyingStream)
{
- m_underlyingStream->flush();
+ DeregisterStream();
Aws::Delete(m_underlyingStream);
}
m_underlyingStream = nullptr;
}
+void ResponseStream::RegisterStream()
+{
+ if (m_underlyingStream)
+ {
+ ResponseStream* pThat = static_cast<ResponseStream*>(m_underlyingStream->pword(ResponseStream::xindex));
+ if (pThat != nullptr)
+ {
+ // callback is already registered
+ assert(pThat != this); // Underlying stream must not be owned by more than one ResponseStream
+ }
+ else
+ {
+ m_underlyingStream->register_callback(ResponseStream::StreamCallback, ResponseStream::xindex);
+ }
+ m_underlyingStream->pword(ResponseStream::xindex) = this;
+ }
+}
+
+void ResponseStream::DeregisterStream()
+{
+ if (m_underlyingStream)
+ {
+ assert(static_cast<ResponseStream*>(m_underlyingStream->pword(ResponseStream::xindex)) == this); // Attempt to deregister another ResponseStream's stream
+ m_underlyingStream->pword(ResponseStream::xindex) = nullptr; // ios does not support deregister, so just erasing the context
+ }
+}
+
+void ResponseStream::StreamCallback(Aws::IOStream::event evt, std::ios_base& stream, int idx)
+{
+ if (evt == std::ios_base::erase_event)
+ {
+ ResponseStream* pThis = static_cast<ResponseStream*>(stream.pword(idx));
+ if (pThis)
+ {
+ // m_underlyingStream is being destructed, let's avoid double destruction or having a dangling pointer
+ pThis->m_underlyingStream = nullptr;
+ }
+ }
+}
+
static const char *DEFAULT_STREAM_TAG = "DefaultUnderlyingStream";
DefaultUnderlyingStream::DefaultUnderlyingStream() :
diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/SimpleStreamBuf.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/SimpleStreamBuf.cpp
index 6e42994744..dbf77ab646 100644
--- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/SimpleStreamBuf.cpp
+++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/stream/SimpleStreamBuf.cpp
@@ -5,6 +5,7 @@
*/
#include <aws/core/utils/stream/SimpleStreamBuf.h>
+#include <aws/core/utils/logging/LogMacros.h>
#include <algorithm>
#include <cassert>
@@ -123,7 +124,14 @@ bool SimpleStreamBuf::GrowBuffer()
if(currentSize > 0)
{
- std::memcpy(newBuffer, m_buffer, currentSize);
+ if(m_buffer)
+ {
+ std::memcpy(newBuffer, m_buffer, currentSize);
+ }
+ else
+ {
+ AWS_LOGSTREAM_FATAL(SIMPLE_STREAMBUF_ALLOCATION_TAG, "Unexpected nullptr m_buffer");
+ }
}
if(m_buffer)