From ffd0860e008eba4edf6f54fa5b75d4ad882d463c Mon Sep 17 00:00:00 2001 From: Ahson Khan Date: Tue, 11 May 2021 20:03:14 -0700 Subject: [PATCH] Avoid using WinHttpQueryDataAvailable, and use WinHttpReadData directly for better throughput. (#2245) * Avoid using WinHttpQueryDataAvailable, and use WinHttpReadData directly for better throughput. * Add back new line at end of file. * Reorder some lines for readability. --- .../src/http/winhttp/win_http_transport.cpp | 33 ++----------------- 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/sdk/core/azure-core/src/http/winhttp/win_http_transport.cpp b/sdk/core/azure-core/src/http/winhttp/win_http_transport.cpp index a50f7aff6..ea9e09a74 100644 --- a/sdk/core/azure-core/src/http/winhttp/win_http_transport.cpp +++ b/sdk/core/azure-core/src/http/winhttp/win_http_transport.cpp @@ -587,43 +587,16 @@ int64_t _detail::WinHttpStream::OnRead(uint8_t* buffer, int64_t count, Context c return 0; } - DWORD numberOfBytesRead = 0; - // No need to check for context cancellation before the first I/O because the base class // BodyStream::Read already does that. + (void)context; - // Check for available data. - DWORD numberOfBytesAvailable = 0; - if (!WinHttpQueryDataAvailable(this->m_handleManager->m_requestHandle, &numberOfBytesAvailable)) - { - // Errors include: - // ERROR_WINHTTP_CONNECTION_ERROR - // ERROR_WINHTTP_INCORRECT_HANDLE_STATE - // ERROR_WINHTTP_INCORRECT_HANDLE_TYPE - // ERROR_WINHTTP_INTERNAL_ERROR - // ERROR_WINHTTP_OPERATION_CANCELLED - // ERROR_WINHTTP_TIMEOUT - // ERROR_NOT_ENOUGH_MEMORY - - DWORD error = GetLastError(); - throw Azure::Core::Http::TransportException( - "Error while querying how much data is available to read. Error Code: " - + std::to_string(error) + "."); - } - - DWORD numberOfBytesToRead = numberOfBytesAvailable; - if (numberOfBytesAvailable > count) - { - numberOfBytesToRead = static_cast(count); - } - - // Check context cancellation again before the next I/O - context.ThrowIfCancelled(); + DWORD numberOfBytesRead = 0; if (!WinHttpReadData( this->m_handleManager->m_requestHandle, (LPVOID)(buffer), - numberOfBytesToRead, + static_cast(count), &numberOfBytesRead)) { // Errors include: