Synchronous operation. GetLastError = 0, WinHttpQueryDataAvailable itself returns TRUE (i.e. OK) yet the number of bytes to read = 0
Any idea what this means? It normally works fine (reading JPEG stream from a camera), but occasionally gets stuck here (which prompts the code to reconnect).
According to MSDN, WinHttpQueryDataAvailable shouldn’t have returned: “If the session is synchronous, the request waits until data becomes available.”
Code extract here:
g_HSession = WinHttpOpen( L"Jet", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0 );
ResultsOk = WinHttpSendRequest(
hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS,
0, WINHTTP_NO_REQUEST_DATA, 0,
0, 0);
// End the request.
if (ResultsOk)
{
ResultsOk = WinHttpReceiveResponse( hRequest, NULL );
DWORD BytesToRead = 0;
if (WinHttpQueryDataAvailable( hRequest, &BytesToRead ))
{
if (BytesToRead) // THIS IS SOMETIMES 0 - seems wrong to me
{
if (WinHttpReadData( hRequest, pReadPos, min(BytesToRead, (unsigned)SizeRemaining), &NumRead ))
{
...etc!
Underlying HTTP response has been successfully received, but it was empty (that is, zero length response) or all the data has been read and closed.
WinHttpQueryDataAvailableindicates this by returningTRUEstill showing zero count of data available.Think of: