[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2143
  • Last Modified:

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;
}
0
gelbert
Asked:
gelbert
  • 2
1 Solution
 
jymmealeyCommented:
Is the InternetReadFileEx returning 0 for dwError when it is complete or is it erroring?  

Is the buffersize, uiCount - 1, big enough to hold all the data?
0
 
jymmealeyCommented:
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.  
0
 
gelbertAuthor Commented:
I am sorry that I did not replied in time. InetBuff.dwBufferTotal returns exact number of data sent including garbage, buffer size is big enough and InternetReadFileEx() returned success. Issue is still unresolved, but I believe that server returns invalid XML.
Thank you for your help and I will assign you points
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now