bool ReadImpl()

in src/aws-cpp-sdk-core/source/http/crt/CRTHttpClient.cpp [37:93]


    bool ReadImpl(Aws::Crt::ByteBuf &buffer) noexcept override
    {
        if (!m_client.ContinueRequest(m_currentRequest) || !m_client.IsRequestProcessingEnabled())
        {
            return false;
        }

        // initial check to see if we should avoid reading for the moment.
        if (!m_rateLimiter || (m_rateLimiter && m_rateLimiter->ApplyCost(0) == std::chrono::milliseconds(0))) {
            size_t currentPos = buffer.len;

            // now do the read. We may over read by an IO buffer size, but it's fine. The throttle will still
            // kick-in in plenty of time.
            bool retValue = false;
            if (!m_isStreaming)
            {
                retValue = Aws::Crt::Io::StdIOStreamInputStream::ReadImpl(buffer);
            }
            else
            {
                if (StdIOStreamInputStream::GetStatusImpl().is_valid && StdIOStreamInputStream::PeekImpl() != std::char_traits<char>::eof())
                {
                    retValue = Aws::Crt::Io::StdIOStreamInputStream::ReadSomeImpl(buffer);
                }
            }
            size_t newPos = buffer.len;
            AWS_ASSERT(newPos >= currentPos && "the buffer length should not have decreased in value.");

            if (retValue && m_isStreaming)
            {
                Aws::Crt::Io::StreamStatus streamStatus;
                GetStatus(streamStatus);

                if (newPos == currentPos && !streamStatus.is_end_of_stream && streamStatus.is_valid)
                {
                    return true;
                }
            }

            size_t amountRead = newPos - currentPos;

            auto& sentHandler = m_currentRequest.GetDataSentEventHandler();
            if (sentHandler)
            {
                sentHandler(&m_currentRequest, static_cast<long long>(amountRead));
            }

            if (m_rateLimiter)
            {
                // now actually reduce the window.
                m_rateLimiter->ApplyCost(static_cast<int64_t>(newPos - currentPos));
                return retValue;
            }
        }

        return true;
    }