Solved

CInternetSession - invalid handle type

Posted on 2002-07-27
3
788 Views
Last Modified: 2013-11-20
I use CInternetSession to get HTTP files. My application is multi-threaded. The code to get the files is like this:


CHttpConnection* pServer = NULL;
     CHttpFile* pFile = NULL;

    TRY
    {
          if (mysession == NULL) mysession = &defaultsession;
          mysession->SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, 1000 * 20);
          mysession->SetOption(INTERNET_OPTION_CONNECT_BACKOFF, 1000);
          mysession->SetOption(INTERNET_OPTION_CONNECT_RETRIES, 2);

          CString s = url;
          //CStdioFile *remotefile = mysession.OpenURL(s,1,INTERNET_FLAG_TRANSFER_BINARY);
         
          CString strServerName;
          CString strObject;
          INTERNET_PORT nPort;
          DWORD dwServiceType;
          const TCHAR szHeaders[] =_T("Accept: */*\r\n");

          if (!AfxParseURL(s, dwServiceType, strServerName, strObject, nPort))
          {
          }
          //DWORD time = GetTickCount();
          pServer = mysession->GetHttpConnection(strServerName, nPort);
          //TRACE("get connection:%d\n",GetTickCount()-time);
          //time = GetTickCount();
          pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject);
          pFile->AddRequestHeaders(szHeaders);
          if (!pFile->SendRequest()) {
               AfxMessageBox("Failed");
               THROW(new CException());
          }
         
          //TRACE("Send request:%d\n",GetTickCount()-time);
          //time = GetTickCount();
     
          DWORD dwRet;
          pFile->QueryInfoStatusCode(dwRet);

Error occurs at QueryInfoStatusCode call. The stack trace is:

CInternetFile::AssertValid() line 1307 + 25 bytes
CHttpFile::AssertValid() line 2281
AfxAssertValidObject(const CObject * 0x009e31c0 {FILE*=0x00000000 name=???}, const char * 0x5f4cdb80 THIS_FILE, int 2225) line 108
CHttpFile::QueryInfoStatusCode(unsigned long & 3435973836) line 2226
GetHttpFile(CString {"http://203.239.186.211:8080/webdemo/kyoto/map01.ipq/a1"}, unsigned char * & 0xcccccccc, int & -858993460, CInternetSession * 0x009e5678 {CInternetSession}) line 468

The code of CInternetFile where error occurs is:

if (IsKindOf(RUNTIME_CLASS(CHttpFile)))
          {
               ASSERT(dwResult == INTERNET_HANDLE_TYPE_HTTP_REQUEST);
          }

Value of dwResult is 4096 (INTERNET_HANDLE_TYPE_HTTP_REQUEST is 13).

I have one default session for generic requests (single threaded), some other sessions (one at a time) to retrieves many files (multi-threaded). The errors occurs on both types of session.
Any idea to get over this?
0
Comment
Question by:daitt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Expert Comment

by:migel
ID: 7184658
Hi!
it seems like OpenRequest return wrong pointer
can you check every WinInet Call result?
You can call GetLastError API to get WinInet call reslts.
0
 
LVL 3

Author Comment

by:daitt
ID: 7342927
The problem was that multi threads accessing the same internet session may cause problem. I think Internet session is not thread-safe. I create separated internet session for each thread and it's ok now.
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 7471702
Per request, points refunded and question closed.

Netminder
CS Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
difference between String.subString() and String.subSequence() 6 292
twoTwo  challenge 35 120
scoreUp challenge 14 74
noX challenge 17 144
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question