Skip to content

Commit d3f7c22

Browse files
committed
changing the size to fix size
1 parent e047ab3 commit d3f7c22

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

src/aws-cpp-sdk-core/include/smithy/client/features/ChunkingInterceptor.h

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,13 @@ class AwsChunkedStreamBuf : public std::streambuf {
5050
return traits_type::to_int_type(*gptr());
5151
}
5252

53-
// Compact buffer when consumed data exceeds half buffer size
54-
if (m_chunkingBufferPos > m_chunkingBuffer.GetLength() / 2) {
55-
size_t remaining = m_chunkingBufferSize - m_chunkingBufferPos;
56-
if (remaining > 0) {
57-
std::memmove(m_chunkingBuffer.GetUnderlyingData(),
58-
m_chunkingBuffer.GetUnderlyingData() + m_chunkingBufferPos,
59-
remaining);
60-
}
61-
m_chunkingBufferSize = remaining;
62-
m_chunkingBufferPos = 0;
63-
}
64-
6553
// only read and write to chunked stream if the underlying stream
6654
// is still in a valid state and we have buffer space
67-
if (m_stream->good()) {
55+
if (m_stream->good() && m_chunkingBufferPos >= m_chunkingBufferSize) {
56+
// Reset buffer for new data only when buffer is consumed
57+
m_chunkingBufferPos = 0;
58+
m_chunkingBufferSize = 0;
59+
6860
// Check if we have enough space for worst-case chunk (data + header + footer)
6961
size_t maxChunkSize = m_data.GetLength() + 20; // data + hex header + CRLF
7062
if (m_chunkingBufferSize + maxChunkSize <= m_chunkingBuffer.GetLength()) {
@@ -132,7 +124,8 @@ class AwsChunkedStreamBuf : public std::streambuf {
132124
}
133125
}
134126

135-
Aws::Utils::Array<char> m_chunkingBuffer{DataBufferSize * 4};
127+
// Buffer for chunked data plus overhead for HTTP chunked encoding headers, trailers, and safety margin
128+
Aws::Utils::Array<char> m_chunkingBuffer{DataBufferSize + 128};
136129
size_t m_chunkingBufferSize{0};
137130
size_t m_chunkingBufferPos{0};
138131
Aws::Http::HttpRequest* m_request{nullptr};

0 commit comments

Comments
 (0)