Use size_t for buffers representing data in memory rather than int64_t. (#2285)
* Use size_t for buffers representing data in memory rather than int64_t. * add a cast from size_t to int64_t * Address feedback - OnRead return size_t. * Change Read and ReadToCount to return size_t instead of int64_t. * Update curl usage and ReadFromSocket. * Missed one signature. * Update changelog. * Update transport layer to use the right size_t size. * Fix curl use of MBS. * Cast to size_t since that's all memory stream supprts. * Add static casts to size_t as temporary workarounds. * update storage tests. * More test fixes.
This commit is contained in:
parent
d6d5120931
commit
65821ec115
@ -12,6 +12,7 @@
|
||||
- Removed `Context::GetApplicationContext()` in favor of a new static data member `Context::ApplicationContext`.
|
||||
- Renamed `Request::IsDownloadViaStream()` to `ShouldBufferResponse()`.
|
||||
- Removed the `Azure::Core::Http::Request` ctor overload that takes both a `bodyStream` and a `bufferedDownload` boolean since it is not useful.
|
||||
- Changed integer size parameters for buffers from `int64_t` to `size_t` in various places such as `Azure::Core::IO::BodyStream::Read()` APIs.
|
||||
- Removed the `Azure::Core::Diagnostics::Logger::Listener` typedef.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
@ -32,8 +32,8 @@ namespace Azure { namespace Core { namespace Http {
|
||||
|
||||
namespace _detail {
|
||||
|
||||
constexpr static int64_t DefaultUploadChunkSize = 1024 * 64;
|
||||
constexpr static int64_t MaximumUploadChunkSize = 1024 * 1024;
|
||||
constexpr static size_t DefaultUploadChunkSize = 1024 * 64;
|
||||
constexpr static size_t MaximumUploadChunkSize = 1024 * 1024;
|
||||
|
||||
struct HandleManager final
|
||||
{
|
||||
@ -104,7 +104,7 @@ namespace Azure { namespace Core { namespace Http {
|
||||
* @param count The number of bytes to read from the network.
|
||||
* @return The actual number of bytes read from the network.
|
||||
*/
|
||||
int64_t OnRead(uint8_t* buffer, int64_t count, Azure::Core::Context const& context) override;
|
||||
size_t OnRead(uint8_t* buffer, size_t count, Azure::Core::Context const& context) override;
|
||||
|
||||
public:
|
||||
WinHttpStream(std::unique_ptr<HandleManager> handleManager, int64_t contentLength)
|
||||
|
||||
@ -18,7 +18,7 @@ namespace Azure { namespace Core { namespace IO { namespace _internal {
|
||||
*/
|
||||
class NullBodyStream final : public BodyStream {
|
||||
private:
|
||||
int64_t OnRead(uint8_t* buffer, int64_t count, Azure::Core::Context const& context) override
|
||||
size_t OnRead(uint8_t* buffer, size_t count, Azure::Core::Context const& context) override
|
||||
{
|
||||
(void)context;
|
||||
(void)buffer;
|
||||
|
||||
@ -42,7 +42,7 @@ namespace Azure { namespace Core { namespace IO {
|
||||
*
|
||||
* @return Number of bytes read.
|
||||
*/
|
||||
virtual int64_t OnRead(uint8_t* buffer, int64_t count, Azure::Core::Context const& context) = 0;
|
||||
virtual size_t OnRead(uint8_t* buffer, size_t count, Azure::Core::Context const& context) = 0;
|
||||
|
||||
public:
|
||||
/// Destructor.
|
||||
@ -77,9 +77,9 @@ namespace Azure { namespace Core { namespace IO {
|
||||
*
|
||||
* @return Number of bytes read.
|
||||
*/
|
||||
int64_t Read(
|
||||
size_t Read(
|
||||
uint8_t* buffer,
|
||||
int64_t count,
|
||||
size_t count,
|
||||
Azure::Core::Context const& context = Azure::Core::Context())
|
||||
{
|
||||
context.ThrowIfCancelled();
|
||||
@ -96,9 +96,9 @@ namespace Azure { namespace Core { namespace IO {
|
||||
*
|
||||
* @return Number of bytes read.
|
||||
*/
|
||||
int64_t ReadToCount(
|
||||
size_t ReadToCount(
|
||||
uint8_t* buffer,
|
||||
int64_t count,
|
||||
size_t count,
|
||||
Azure::Core::Context const& context = Azure::Core::Context());
|
||||
|
||||
/**
|
||||
@ -119,10 +119,10 @@ namespace Azure { namespace Core { namespace IO {
|
||||
class MemoryBodyStream final : public BodyStream {
|
||||
private:
|
||||
const uint8_t* m_data;
|
||||
int64_t m_length;
|
||||
int64_t m_offset = 0;
|
||||
size_t m_length;
|
||||
size_t m_offset = 0;
|
||||
|
||||
int64_t OnRead(uint8_t* buffer, int64_t count, Azure::Core::Context const& context) override;
|
||||
size_t OnRead(uint8_t* buffer, size_t count, Azure::Core::Context const& context) override;
|
||||
|
||||
public:
|
||||
// Forbid constructor for rval so we don't end up storing dangling ptr
|
||||
@ -134,7 +134,7 @@ namespace Azure { namespace Core { namespace IO {
|
||||
* @param buffer Vector of bytes with the contents to provide the data from to the readers.
|
||||
*/
|
||||
MemoryBodyStream(std::vector<uint8_t> const& buffer)
|
||||
: MemoryBodyStream(buffer.data(), static_cast<int64_t>(buffer.size()))
|
||||
: MemoryBodyStream(buffer.data(), buffer.size())
|
||||
{
|
||||
}
|
||||
|
||||
@ -145,7 +145,7 @@ namespace Azure { namespace Core { namespace IO {
|
||||
* from to the readers.
|
||||
* @param length Size of the buffer.
|
||||
*/
|
||||
explicit MemoryBodyStream(const uint8_t* data, int64_t length) : m_data(data), m_length(length)
|
||||
explicit MemoryBodyStream(const uint8_t* data, size_t length) : m_data(data), m_length(length)
|
||||
{
|
||||
}
|
||||
|
||||
@ -172,7 +172,7 @@ namespace Azure { namespace Core { namespace IO {
|
||||
// mutable
|
||||
int64_t m_offset;
|
||||
|
||||
int64_t OnRead(uint8_t* buffer, int64_t count, Azure::Core::Context const& context) override;
|
||||
size_t OnRead(uint8_t* buffer, size_t count, Azure::Core::Context const& context) override;
|
||||
|
||||
public:
|
||||
#if defined(AZ_PLATFORM_POSIX)
|
||||
@ -247,7 +247,7 @@ namespace Azure { namespace Core { namespace IO {
|
||||
// mutable
|
||||
std::unique_ptr<_internal::RandomAccessFileBodyStream> m_randomAccessFileBodyStream;
|
||||
|
||||
int64_t OnRead(uint8_t* buffer, int64_t count, Azure::Core::Context const& context) override;
|
||||
size_t OnRead(uint8_t* buffer, size_t count, Azure::Core::Context const& context) override;
|
||||
|
||||
public:
|
||||
/**
|
||||
|
||||
@ -531,14 +531,13 @@ CURLcode CurlSession::UploadBody(Context const& context)
|
||||
|
||||
while (true)
|
||||
{
|
||||
auto rawRequestLen
|
||||
size_t rawRequestLen
|
||||
= streamBody->Read(unique_buffer.get(), _detail::DefaultUploadChunkSize, context);
|
||||
if (rawRequestLen == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
sendResult = m_connection->SendBuffer(
|
||||
unique_buffer.get(), static_cast<size_t>(rawRequestLen), context);
|
||||
sendResult = m_connection->SendBuffer(unique_buffer.get(), rawRequestLen, context);
|
||||
if (sendResult != CURLE_OK)
|
||||
{
|
||||
return sendResult;
|
||||
@ -780,9 +779,9 @@ void CurlSession::ReadCRLF(Context const& context)
|
||||
}
|
||||
|
||||
// Read from curl session
|
||||
int64_t CurlSession::OnRead(uint8_t* buffer, int64_t count, Context const& context)
|
||||
size_t CurlSession::OnRead(uint8_t* buffer, size_t count, Context const& context)
|
||||
{
|
||||
if (count <= 0 || this->IsEOF())
|
||||
if (count == 0 || this->IsEOF())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -807,10 +806,10 @@ int64_t CurlSession::OnRead(uint8_t* buffer, int64_t count, Context const& conte
|
||||
}
|
||||
}
|
||||
|
||||
auto totalRead = int64_t();
|
||||
auto readRequestLength = this->m_isChunkedResponseType
|
||||
? (std::min)(this->m_chunkSize - this->m_sessionTotalRead, count)
|
||||
: count;
|
||||
auto totalRead = size_t();
|
||||
int64_t readRequestLength = this->m_isChunkedResponseType
|
||||
? (std::min)(this->m_chunkSize - this->m_sessionTotalRead, static_cast<int64_t>(count))
|
||||
: static_cast<int64_t>(count);
|
||||
|
||||
// For responses with content-length, avoid trying to read beyond Content-length or
|
||||
// libcurl could return a second response as BadRequest.
|
||||
@ -825,11 +824,17 @@ int64_t CurlSession::OnRead(uint8_t* buffer, int64_t count, Context const& conte
|
||||
if (this->m_bodyStartInBuffer >= 0)
|
||||
{
|
||||
// still have data to take from innerbuffer
|
||||
// TODO: Change the fields to be size_t for a less error-prone implementation
|
||||
// The casts here are safe to do because we know the buffers and the offset are within the
|
||||
// range.
|
||||
Azure::Core::IO::MemoryBodyStream innerBufferMemoryStream(
|
||||
this->m_readBuffer + this->m_bodyStartInBuffer,
|
||||
this->m_innerBufferSize - this->m_bodyStartInBuffer);
|
||||
static_cast<size_t>(this->m_innerBufferSize - this->m_bodyStartInBuffer));
|
||||
|
||||
totalRead = innerBufferMemoryStream.Read(buffer, readRequestLength, context);
|
||||
// From code inspection, it is guaranteed that the readRequestLength will fit within size_t
|
||||
// since count is bounded by size_t.
|
||||
totalRead
|
||||
= innerBufferMemoryStream.Read(buffer, static_cast<size_t>(readRequestLength), context);
|
||||
this->m_bodyStartInBuffer += totalRead;
|
||||
this->m_sessionTotalRead += totalRead;
|
||||
|
||||
@ -884,7 +889,7 @@ void CurlConnection::Shutdown()
|
||||
}
|
||||
|
||||
// Read from socket and return the number of bytes taken from socket
|
||||
int64_t CurlConnection::ReadFromSocket(uint8_t* buffer, int64_t bufferSize, Context const& context)
|
||||
size_t CurlConnection::ReadFromSocket(uint8_t* buffer, size_t bufferSize, Context const& context)
|
||||
{
|
||||
// loop until read result is not CURLE_AGAIN
|
||||
// Next loop is expected to be called at most 2 times:
|
||||
@ -899,7 +904,7 @@ int64_t CurlConnection::ReadFromSocket(uint8_t* buffer, int64_t bufferSize, Cont
|
||||
size_t readBytes = 0;
|
||||
for (CURLcode readResult = CURLE_AGAIN; readResult == CURLE_AGAIN;)
|
||||
{
|
||||
readResult = curl_easy_recv(m_handle, buffer, static_cast<size_t>(bufferSize), &readBytes);
|
||||
readResult = curl_easy_recv(m_handle, buffer, bufferSize, &readBytes);
|
||||
|
||||
switch (readResult)
|
||||
{
|
||||
|
||||
@ -80,7 +80,7 @@ namespace Azure { namespace Core { namespace Http {
|
||||
* there is no more data to get from the socket.
|
||||
*
|
||||
*/
|
||||
virtual int64_t ReadFromSocket(uint8_t* buffer, int64_t bufferSize, Context const& context) = 0;
|
||||
virtual size_t ReadFromSocket(uint8_t* buffer, size_t bufferSize, Context const& context) = 0;
|
||||
|
||||
/**
|
||||
* @brief This method will use libcurl socket to write all the bytes from buffer.
|
||||
@ -184,7 +184,7 @@ namespace Azure { namespace Core { namespace Http {
|
||||
* @return return the numbers of bytes pulled from socket. It can be less than what it was
|
||||
* requested.
|
||||
*/
|
||||
int64_t ReadFromSocket(uint8_t* buffer, int64_t bufferSize, Context const& context) override;
|
||||
size_t ReadFromSocket(uint8_t* buffer, size_t bufferSize, Context const& context) override;
|
||||
|
||||
/**
|
||||
* @brief This method will use libcurl socket to write all the bytes from buffer.
|
||||
|
||||
@ -362,7 +362,7 @@ namespace Azure { namespace Core { namespace Http {
|
||||
* @param count The number of bytes to read from the network.
|
||||
* @return The actual number of bytes read from the network.
|
||||
*/
|
||||
int64_t OnRead(uint8_t* buffer, int64_t count, Azure::Core::Context const& context) override;
|
||||
size_t OnRead(uint8_t* buffer, size_t count, Azure::Core::Context const& context) override;
|
||||
|
||||
public:
|
||||
/**
|
||||
|
||||
@ -289,16 +289,16 @@ void WinHttpTransport::Upload(std::unique_ptr<_detail::HandleManager>& handleMan
|
||||
int64_t streamLength = streamBody->Length();
|
||||
|
||||
// Consider using `MaximumUploadChunkSize` here, after some perf measurements
|
||||
int64_t uploadChunkSize = _detail::DefaultUploadChunkSize;
|
||||
size_t uploadChunkSize = _detail::DefaultUploadChunkSize;
|
||||
if (streamLength < _detail::MaximumUploadChunkSize)
|
||||
{
|
||||
uploadChunkSize = streamLength;
|
||||
uploadChunkSize = static_cast<size_t>(streamLength);
|
||||
}
|
||||
auto unique_buffer = std::make_unique<uint8_t[]>(static_cast<size_t>(uploadChunkSize));
|
||||
auto unique_buffer = std::make_unique<uint8_t[]>(uploadChunkSize);
|
||||
|
||||
while (true)
|
||||
{
|
||||
auto rawRequestLen
|
||||
size_t rawRequestLen
|
||||
= streamBody->Read(unique_buffer.get(), uploadChunkSize, handleManager->m_context);
|
||||
if (rawRequestLen == 0)
|
||||
{
|
||||
@ -580,9 +580,9 @@ std::unique_ptr<RawResponse> WinHttpTransport::Send(Request& request, Context co
|
||||
}
|
||||
|
||||
// Read the response from the sent request.
|
||||
int64_t _detail::WinHttpStream::OnRead(uint8_t* buffer, int64_t count, Context const& context)
|
||||
size_t _detail::WinHttpStream::OnRead(uint8_t* buffer, size_t count, Context const& context)
|
||||
{
|
||||
if (count <= 0 || this->m_isEOF)
|
||||
if (count == 0 || this->m_isEOF)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -40,13 +40,13 @@ static_assert(sizeof(void*) >= sizeof(HANDLE), "We must be able to cast HANDLE t
|
||||
#endif
|
||||
|
||||
// Keep reading until buffer is all fill out of the end of stream content is reached
|
||||
int64_t BodyStream::ReadToCount(uint8_t* buffer, int64_t count, Context const& context)
|
||||
size_t BodyStream::ReadToCount(uint8_t* buffer, size_t count, Context const& context)
|
||||
{
|
||||
int64_t totalRead = 0;
|
||||
size_t totalRead = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int64_t readBytes = this->Read(buffer + totalRead, count - totalRead, context);
|
||||
size_t readBytes = this->Read(buffer + totalRead, count - totalRead, context);
|
||||
totalRead += readBytes;
|
||||
// Reach all of buffer size
|
||||
if (totalRead == count || readBytes == 0)
|
||||
@ -58,13 +58,13 @@ int64_t BodyStream::ReadToCount(uint8_t* buffer, int64_t count, Context const& c
|
||||
|
||||
std::vector<uint8_t> BodyStream::ReadToEnd(Context const& context)
|
||||
{
|
||||
constexpr int64_t chunkSize = 1024 * 8;
|
||||
constexpr size_t chunkSize = 1024 * 8;
|
||||
auto buffer = std::vector<uint8_t>();
|
||||
|
||||
for (auto chunkNumber = 0;; chunkNumber++)
|
||||
{
|
||||
buffer.resize((static_cast<decltype(buffer)::size_type>(chunkNumber) + 1) * chunkSize);
|
||||
int64_t readBytes
|
||||
size_t readBytes
|
||||
= this->ReadToCount(buffer.data() + (chunkNumber * chunkSize), chunkSize, context);
|
||||
|
||||
if (readBytes < chunkSize)
|
||||
@ -75,10 +75,10 @@ std::vector<uint8_t> BodyStream::ReadToEnd(Context const& context)
|
||||
}
|
||||
}
|
||||
|
||||
int64_t MemoryBodyStream::OnRead(uint8_t* buffer, int64_t count, Context const& context)
|
||||
size_t MemoryBodyStream::OnRead(uint8_t* buffer, size_t count, Context const& context)
|
||||
{
|
||||
(void)context;
|
||||
int64_t copy_length = std::min(count, static_cast<int64_t>(this->m_length - this->m_offset));
|
||||
size_t copy_length = std::min(count, this->m_length - this->m_offset);
|
||||
// Copy what's left or just the count
|
||||
std::memcpy(buffer, this->m_data + m_offset, static_cast<size_t>(copy_length));
|
||||
// move position
|
||||
@ -175,7 +175,7 @@ FileBodyStream::~FileBodyStream()
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t FileBodyStream::OnRead(uint8_t* buffer, int64_t count, Azure::Core::Context const& context)
|
||||
size_t FileBodyStream::OnRead(uint8_t* buffer, size_t count, Azure::Core::Context const& context)
|
||||
{
|
||||
return m_randomAccessFileBodyStream->Read(buffer, count, context);
|
||||
}
|
||||
|
||||
@ -26,18 +26,19 @@
|
||||
using Azure::Core::Context;
|
||||
using namespace Azure::Core::IO::_internal;
|
||||
|
||||
int64_t RandomAccessFileBodyStream::OnRead(
|
||||
size_t RandomAccessFileBodyStream::OnRead(
|
||||
uint8_t* buffer,
|
||||
int64_t count,
|
||||
size_t count,
|
||||
Azure::Core::Context const&)
|
||||
{
|
||||
|
||||
#if defined(AZ_PLATFORM_POSIX)
|
||||
|
||||
// Returning ssize_t from pread as a size_t is fine since we do a `< 0` check below and throw.
|
||||
auto numberOfBytesRead = pread(
|
||||
this->m_fileDescriptor,
|
||||
buffer,
|
||||
std::min(count, this->m_length - this->m_offset),
|
||||
std::min(static_cast<int64_t>(count), this->m_length - this->m_offset),
|
||||
this->m_baseOffset + this->m_offset);
|
||||
|
||||
if (numberOfBytesRead < 0)
|
||||
@ -60,7 +61,8 @@ int64_t RandomAccessFileBodyStream::OnRead(
|
||||
// at most 4Gb to be read
|
||||
static_cast<DWORD>(std::min(
|
||||
static_cast<uint64_t>(0xFFFFFFFFUL),
|
||||
static_cast<uint64_t>(std::min(count, (this->m_length - this->m_offset))))),
|
||||
static_cast<uint64_t>(
|
||||
std::min(static_cast<int64_t>(count), (this->m_length - this->m_offset))))),
|
||||
&numberOfBytesRead,
|
||||
&o);
|
||||
|
||||
|
||||
@ -80,7 +80,7 @@ namespace Azure { namespace Core { namespace Http {
|
||||
* there is no more data to get from the socket.
|
||||
*
|
||||
*/
|
||||
virtual int64_t ReadFromSocket(uint8_t* buffer, int64_t bufferSize, Context const& context) = 0;
|
||||
virtual size_t ReadFromSocket(uint8_t* buffer, size_t bufferSize, Context const& context) = 0;
|
||||
|
||||
/**
|
||||
* @brief This method will use libcurl socket to write all the bytes from buffer.
|
||||
@ -184,7 +184,7 @@ namespace Azure { namespace Core { namespace Http {
|
||||
* @return return the numbers of bytes pulled from socket. It can be less than what it was
|
||||
* requested.
|
||||
*/
|
||||
int64_t ReadFromSocket(uint8_t* buffer, int64_t bufferSize, Context const& context) override;
|
||||
size_t ReadFromSocket(uint8_t* buffer, size_t bufferSize, Context const& context) override;
|
||||
|
||||
/**
|
||||
* @brief This method will use libcurl socket to write all the bytes from buffer.
|
||||
|
||||
@ -362,7 +362,7 @@ namespace Azure { namespace Core { namespace Http {
|
||||
* @param count The number of bytes to read from the network.
|
||||
* @return The actual number of bytes read from the network.
|
||||
*/
|
||||
int64_t OnRead(uint8_t* buffer, int64_t count, Azure::Core::Context const& context) override;
|
||||
size_t OnRead(uint8_t* buffer, size_t count, Azure::Core::Context const& context) override;
|
||||
|
||||
public:
|
||||
/**
|
||||
|
||||
@ -26,7 +26,7 @@ using namespace Azure::Core;
|
||||
|
||||
// Used to test virtual, default behavior of BodyStream.
|
||||
class TestBodyStream final : public BodyStream {
|
||||
int64_t OnRead(uint8_t*, int64_t, Context const&) override { return 0; }
|
||||
size_t OnRead(uint8_t*, size_t, Context const&) override { return 0; }
|
||||
int64_t Length() const override { return 0; }
|
||||
};
|
||||
|
||||
@ -97,7 +97,7 @@ TEST(FileBodyStream, Read)
|
||||
// ReadToCount
|
||||
std::vector<uint8_t> buffer(FileSize * 2);
|
||||
|
||||
int64_t readSize = stream.ReadToCount(buffer.data(), 10);
|
||||
size_t readSize = stream.ReadToCount(buffer.data(), 10);
|
||||
EXPECT_EQ(readSize, 10);
|
||||
EXPECT_EQ(buffer[10], 0);
|
||||
|
||||
|
||||
@ -41,9 +41,9 @@ namespace Azure { namespace Core { namespace Test {
|
||||
MOCK_METHOD(void, UpdateLastUsageTime, (), (override));
|
||||
MOCK_METHOD(bool, IsExpired, (), (override));
|
||||
MOCK_METHOD(
|
||||
int64_t,
|
||||
size_t,
|
||||
ReadFromSocket,
|
||||
(uint8_t * buffer, int64_t bufferSize, Context const& context),
|
||||
(uint8_t * buffer, size_t bufferSize, Context const& context),
|
||||
(override));
|
||||
MOCK_METHOD(
|
||||
CURLcode,
|
||||
|
||||
@ -34,10 +34,10 @@ inline std::vector<uint8_t> CreateDigest(
|
||||
auto heapBuffer = std::make_unique<std::vector<uint8_t>>(DefaultStreamDigestReadSize);
|
||||
auto* buffer = heapBuffer.get()->data();
|
||||
auto hashAlgorithm = algorithm.GetHashAlgorithm();
|
||||
for (uint64_t read = data.Read(buffer, DefaultStreamDigestReadSize); read > 0;
|
||||
for (size_t read = data.Read(buffer, DefaultStreamDigestReadSize); read > 0;
|
||||
read = data.Read(buffer, DefaultStreamDigestReadSize))
|
||||
{
|
||||
hashAlgorithm->Append(buffer, static_cast<size_t>(read));
|
||||
hashAlgorithm->Append(buffer, read);
|
||||
}
|
||||
return hashAlgorithm->Final();
|
||||
}
|
||||
|
||||
@ -264,7 +264,8 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
"buffer is not big enough, blob range size is " + std::to_string(blobRangeSize));
|
||||
}
|
||||
|
||||
int64_t bytesRead = firstChunk.Value.BodyStream->ReadToCount(buffer, firstChunkLength, context);
|
||||
int64_t bytesRead = firstChunk.Value.BodyStream->ReadToCount(
|
||||
buffer, static_cast<size_t>(firstChunkLength), context);
|
||||
if (bytesRead != firstChunkLength)
|
||||
{
|
||||
throw Azure::Core::RequestFailedException("error when reading body stream");
|
||||
@ -297,7 +298,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
auto chunk = Download(chunkOptions, context);
|
||||
int64_t bytesRead = chunk.Value.BodyStream->ReadToCount(
|
||||
buffer + (offset - firstChunkOffset),
|
||||
chunkOptions.Range.Value().Length.Value(),
|
||||
static_cast<size_t>(chunkOptions.Range.Value().Length.Value()),
|
||||
context);
|
||||
if (bytesRead != chunkOptions.Range.Value().Length.Value())
|
||||
{
|
||||
@ -378,7 +379,8 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
while (length > 0)
|
||||
{
|
||||
int64_t readSize = std::min(static_cast<int64_t>(bufferSize), length);
|
||||
int64_t bytesRead = stream.ReadToCount(buffer.data(), readSize, context);
|
||||
int64_t bytesRead
|
||||
= stream.ReadToCount(buffer.data(), static_cast<size_t>(readSize), context);
|
||||
if (bytesRead != readSize)
|
||||
{
|
||||
throw Azure::Core::RequestFailedException("error when reading body stream");
|
||||
|
||||
@ -163,7 +163,9 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
};
|
||||
|
||||
auto uploadBlockFunc = [&](int64_t offset, int64_t length, int64_t chunkId, int64_t numChunks) {
|
||||
Azure::Core::IO::MemoryBodyStream contentStream(buffer + offset, length);
|
||||
// TODO: Investigate changing lambda parameters to be size_t, unless they need to be int64_t
|
||||
// for some reason.
|
||||
Azure::Core::IO::MemoryBodyStream contentStream(buffer + offset, static_cast<size_t>(length));
|
||||
StageBlockOptions chunkOptions;
|
||||
auto blockInfo = StageBlock(getBlockId(chunkId), contentStream, chunkOptions, context);
|
||||
if (chunkId == numChunks - 1)
|
||||
|
||||
@ -774,7 +774,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
|
||||
std::vector<uint8_t> contentData(512);
|
||||
int64_t contentSize = static_cast<int64_t>(contentData.size());
|
||||
auto content = Azure::Core::IO::MemoryBodyStream(contentData.data(), contentSize);
|
||||
auto content = Azure::Core::IO::MemoryBodyStream(contentData.data(), contentData.size());
|
||||
|
||||
std::string blobName = RandomString();
|
||||
auto appendBlobClient = Azure::Storage::Blobs::AppendBlobClient::CreateFromConnectionString(
|
||||
|
||||
@ -131,7 +131,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
static_cast<int64_t>(m_primaryContent->length()) - requestOffset, requestLength);
|
||||
auto bodyStream = std::make_unique<Core::IO::MemoryBodyStream>(
|
||||
reinterpret_cast<const uint8_t*>(m_primaryContent->data() + requestOffset),
|
||||
bodyLength);
|
||||
static_cast<size_t>(bodyLength));
|
||||
response->SetBodyStream(std::move(bodyStream));
|
||||
response->SetHeader("content-length", std::to_string(bodyLength));
|
||||
response->SetHeader("etag", m_primaryETag.ToString());
|
||||
@ -161,7 +161,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
static_cast<int64_t>(m_secondaryContent->length()) - requestOffset, requestLength);
|
||||
auto bodyStream = std::make_unique<Core::IO::MemoryBodyStream>(
|
||||
reinterpret_cast<const uint8_t*>(m_secondaryContent->data() + requestOffset),
|
||||
bodyLength);
|
||||
static_cast<size_t>(bodyLength));
|
||||
response->SetBodyStream(std::move(bodyStream));
|
||||
response->SetHeader("content-length", std::to_string(bodyLength));
|
||||
response->SetHeader("etag", m_secondaryETag.ToString());
|
||||
|
||||
@ -42,7 +42,7 @@ namespace Azure { namespace Storage { namespace _internal {
|
||||
// Options to use when getting a new bodyStream like current offset
|
||||
int64_t m_retryOffset;
|
||||
|
||||
int64_t OnRead(uint8_t* buffer, int64_t count, Azure::Core::Context const& context) override;
|
||||
size_t OnRead(uint8_t* buffer, size_t count, Azure::Core::Context const& context) override;
|
||||
|
||||
public:
|
||||
explicit ReliableStream(
|
||||
|
||||
@ -10,7 +10,7 @@ using Azure::Core::IO::BodyStream;
|
||||
|
||||
namespace Azure { namespace Storage { namespace _internal {
|
||||
|
||||
int64_t ReliableStream::OnRead(uint8_t* buffer, int64_t count, Context const& context)
|
||||
size_t ReliableStream::OnRead(uint8_t* buffer, size_t count, Context const& context)
|
||||
{
|
||||
(void)context;
|
||||
for (int64_t intent = 1;; intent++)
|
||||
|
||||
@ -694,7 +694,8 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
|
||||
"buffer is not big enough, file range size is " + std::to_string(fileRangeSize));
|
||||
}
|
||||
|
||||
int64_t bytesRead = firstChunk.Value.BodyStream->ReadToCount(buffer, firstChunkLength, context);
|
||||
int64_t bytesRead = firstChunk.Value.BodyStream->ReadToCount(
|
||||
buffer, static_cast<size_t>(firstChunkLength), context);
|
||||
if (bytesRead != firstChunkLength)
|
||||
{
|
||||
throw Azure::Core::RequestFailedException("error when reading body stream");
|
||||
@ -721,7 +722,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
|
||||
auto chunk = Download(chunkOptions, context);
|
||||
int64_t bytesRead = chunk.Value.BodyStream->ReadToCount(
|
||||
buffer + (offset - firstChunkOffset),
|
||||
chunkOptions.Range.Value().Length.Value(),
|
||||
static_cast<size_t>(chunkOptions.Range.Value().Length.Value()),
|
||||
context);
|
||||
if (bytesRead != chunkOptions.Range.Value().Length.Value())
|
||||
{
|
||||
@ -802,7 +803,8 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
|
||||
while (length > 0)
|
||||
{
|
||||
int64_t readSize = std::min(static_cast<int64_t>(bufferSize), length);
|
||||
int64_t bytesRead = stream.ReadToCount(buffer.data(), readSize, context);
|
||||
int64_t bytesRead
|
||||
= stream.ReadToCount(buffer.data(), static_cast<size_t>(readSize), context);
|
||||
if (bytesRead != readSize)
|
||||
{
|
||||
throw Azure::Core::RequestFailedException("error when reading body stream");
|
||||
@ -939,7 +941,9 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
|
||||
auto uploadPageFunc = [&](int64_t offset, int64_t length, int64_t chunkId, int64_t numChunks) {
|
||||
(void)chunkId;
|
||||
(void)numChunks;
|
||||
Azure::Core::IO::MemoryBodyStream contentStream(buffer + offset, length);
|
||||
// TODO: Investigate changing lambda parameters to be size_t, unless they need to be int64_t
|
||||
// for some reason.
|
||||
Azure::Core::IO::MemoryBodyStream contentStream(buffer + offset, static_cast<size_t>(length));
|
||||
UploadFileRangeOptions uploadRangeOptions;
|
||||
UploadRange(offset, contentStream, uploadRangeOptions, context);
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user