Async InternetReadFileEx() problem

Question : Async InternetReadFileEx() problem

Hi!
I need to do async communications using HttpSendRequest() and InternetReadFile(). HttpSendRequest() returns ERROR_IO_PENDING and I wait for INTERNET_STATUS_REQUEST_COMPLETE event in OnStatusCallback(), then I call InternetReadFileEx() which returns incomplete data (usually a few hundreds bites short). I would apreciate any help.

DWORD CAsyncSession::SendRequestAsync( CString& strHeaders,
LPVOID lpOptional,
DWORD dwOptionalLen )
{
HINTERNET hHttpFile = m_HttpFile->GetFileHandle();
if ( ::HttpSendRequest( hHttpFile, strHeaders, strHeaders.GetLength(), lpOptional, dwOptionalLen ) )
return 0;
DWORD dwError = ::GetLastError();
if ( ERROR_IO_PENDING != dwError )
AfxThrowInternetException( m_HttpFile->GetContext(), dwError);

return dwError;
}

DWORD CAsyncSession::ReadAsync( LPVOID lpBuf, UINT uiCount, DWORD* pdwError )
{
HINTERNET hHttpFile = m_HttpFile->GetFileHandle();

DWORD dwBytes = 0, dwError = 0;

::SetLastError( 0 );

INTERNET_BUFFERS InetBuff;
FillMemory( &InetBuff, sizeof(InetBuff), 0 );
InetBuff.dwStructSize = sizeof(InetBuff);
InetBuff.lpvBuffer = lpBuf;
InetBuff.dwBufferLength = uiCount – 1;

::InternetReadFileEx( hHttpFile, &InetBuff, 0, m_HttpFile->GetContext() );
dwError = ::GetLastError();
dwBytes = InetBuff.dwBufferLength;
if ( 0 != dwError )
{
if ( pdwError )
*pdwError = dwError;

if ( ERROR_IO_PENDING != dwError )
AfxThrowInternetException( m_HttpFile->GetContext(), dwError);
}
return dwBytes;
}


 

Solution : Async InternetReadFileEx() problem
You can check the amount of data sent from the server by using InetBuff.dwBufferTotal.  This is the total amount of data the server sent.