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.
This commit is contained in:
Ahson Khan 2021-05-11 20:03:14 -07:00 committed by GitHub
parent ebb112f682
commit ffd0860e00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<DWORD>(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<DWORD>(count),
&numberOfBytesRead))
{
// Errors include: