Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CInternetSession Questions.

CInternetSession Questions.

Scheduled Pinned Locked Moved C / C++ / MFC
4 Posts 4 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mike Doner
    wrote on last edited by
    #1

    Hi all... I'm doing some development which queries a PC network by making requests to a file on the host system through HTTP. I'm experimenting with CInternetSession & CHttpFile, and some of the examples of each on this site. I have a few questions/problems: 1) Is there a way I can easily determine the MAC address of the PC I'm connectedly to? 2) I'm encountering lock-up when the hardware becomes disconnected from the network midway through the CHttpFile->Read() operation. This function hangs infinitely. Is there a timeout you can set for this? I countered this problem with the WebGrab Example Here is a snippet: BOOL CWebGrab::GetFile ( LPCTSTR szURL, CString& strBuffer, LPCTSTR szAgentName /*=NULL*/, CWnd* pWnd /*=NULL*/ ) { // TRACE1("URL is %s\n", szURL); m_rawHeaders =""; m_infoStatusCode=0; strBuffer.Empty(); if (!m_pSession && !Initialise(szAgentName, pWnd)) return FALSE; if (pWnd) m_pSession->SetStatusWnd(pWnd); //m_pSession->SetStatus("Downloading file..."); DWORD dwCount = 0; CHttpFile* pFile = NULL; try { pFile = (CHttpFile*) m_pSession->OpenURL(szURL, 1, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE //| INTERNET_OPEN_FLAG_USE_EXISTING_CONNECT | //| INTERNET_FLAG_RELOAD ); } catch (CInternetException* e) { TCHAR szCause[255]; e->GetErrorMessage(szCause, 255); m_pSession->SetStatus(szCause); // e->ReportError(); e->Delete(); delete pFile; pFile = NULL; return FALSE; } COleDateTime startTime = COleDateTime::GetCurrentTime(); LPSTR pBuf = NULL; if (pFile) { pBuf = (LPSTR) ::GlobalAlloc(GMEM_FIXED, BUFFER_SIZE+1); if (!pBuf) { pFile->Close(); delete pFile; return FALSE; } BYTE buffer[BUFFER_SIZE+1]; try { UINT nRead = 0; DWORD size; dwCount = 0; do { **nRead = pFile->Read(buffer, BUFFER_SIZE); - LOCKS HERE waiting for the rest of the bytes.** if (nRead > 0) {

    RaviBeeR L M 3 Replies Last reply
    0
    • M Mike Doner

      Hi all... I'm doing some development which queries a PC network by making requests to a file on the host system through HTTP. I'm experimenting with CInternetSession & CHttpFile, and some of the examples of each on this site. I have a few questions/problems: 1) Is there a way I can easily determine the MAC address of the PC I'm connectedly to? 2) I'm encountering lock-up when the hardware becomes disconnected from the network midway through the CHttpFile->Read() operation. This function hangs infinitely. Is there a timeout you can set for this? I countered this problem with the WebGrab Example Here is a snippet: BOOL CWebGrab::GetFile ( LPCTSTR szURL, CString& strBuffer, LPCTSTR szAgentName /*=NULL*/, CWnd* pWnd /*=NULL*/ ) { // TRACE1("URL is %s\n", szURL); m_rawHeaders =""; m_infoStatusCode=0; strBuffer.Empty(); if (!m_pSession && !Initialise(szAgentName, pWnd)) return FALSE; if (pWnd) m_pSession->SetStatusWnd(pWnd); //m_pSession->SetStatus("Downloading file..."); DWORD dwCount = 0; CHttpFile* pFile = NULL; try { pFile = (CHttpFile*) m_pSession->OpenURL(szURL, 1, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE //| INTERNET_OPEN_FLAG_USE_EXISTING_CONNECT | //| INTERNET_FLAG_RELOAD ); } catch (CInternetException* e) { TCHAR szCause[255]; e->GetErrorMessage(szCause, 255); m_pSession->SetStatus(szCause); // e->ReportError(); e->Delete(); delete pFile; pFile = NULL; return FALSE; } COleDateTime startTime = COleDateTime::GetCurrentTime(); LPSTR pBuf = NULL; if (pFile) { pBuf = (LPSTR) ::GlobalAlloc(GMEM_FIXED, BUFFER_SIZE+1); if (!pBuf) { pFile->Close(); delete pFile; return FALSE; } BYTE buffer[BUFFER_SIZE+1]; try { UINT nRead = 0; DWORD size; dwCount = 0; do { **nRead = pFile->Read(buffer, BUFFER_SIZE); - LOCKS HERE waiting for the rest of the bytes.** if (nRead > 0) {

      RaviBeeR Offline
      RaviBeeR Offline
      RaviBee
      wrote on last edited by
      #2

      Mike Doner wrote:

      Is there a timeout you can set for this?

      Yes, you can use CInternetSession.SetOption() to set various kinds of timeouts. See this[^] page for values. /ravi

      This is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

      1 Reply Last reply
      0
      • M Mike Doner

        Hi all... I'm doing some development which queries a PC network by making requests to a file on the host system through HTTP. I'm experimenting with CInternetSession & CHttpFile, and some of the examples of each on this site. I have a few questions/problems: 1) Is there a way I can easily determine the MAC address of the PC I'm connectedly to? 2) I'm encountering lock-up when the hardware becomes disconnected from the network midway through the CHttpFile->Read() operation. This function hangs infinitely. Is there a timeout you can set for this? I countered this problem with the WebGrab Example Here is a snippet: BOOL CWebGrab::GetFile ( LPCTSTR szURL, CString& strBuffer, LPCTSTR szAgentName /*=NULL*/, CWnd* pWnd /*=NULL*/ ) { // TRACE1("URL is %s\n", szURL); m_rawHeaders =""; m_infoStatusCode=0; strBuffer.Empty(); if (!m_pSession && !Initialise(szAgentName, pWnd)) return FALSE; if (pWnd) m_pSession->SetStatusWnd(pWnd); //m_pSession->SetStatus("Downloading file..."); DWORD dwCount = 0; CHttpFile* pFile = NULL; try { pFile = (CHttpFile*) m_pSession->OpenURL(szURL, 1, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE //| INTERNET_OPEN_FLAG_USE_EXISTING_CONNECT | //| INTERNET_FLAG_RELOAD ); } catch (CInternetException* e) { TCHAR szCause[255]; e->GetErrorMessage(szCause, 255); m_pSession->SetStatus(szCause); // e->ReportError(); e->Delete(); delete pFile; pFile = NULL; return FALSE; } COleDateTime startTime = COleDateTime::GetCurrentTime(); LPSTR pBuf = NULL; if (pFile) { pBuf = (LPSTR) ::GlobalAlloc(GMEM_FIXED, BUFFER_SIZE+1); if (!pBuf) { pFile->Close(); delete pFile; return FALSE; } BYTE buffer[BUFFER_SIZE+1]; try { UINT nRead = 0; DWORD size; dwCount = 0; do { **nRead = pFile->Read(buffer, BUFFER_SIZE); - LOCKS HERE waiting for the rest of the bytes.** if (nRead > 0) {

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #3

        Mike Doner wrote:

        1. I'm encountering lock-up when the hardware becomes disconnected from the network midway through the CHttpFile->Read() operation. This function hangs infinitely. Is there a timeout you can set for this?

        No and hanging should not happen. When the physical network is no longer available the read() should unblock and WSAGetLastError() should return an error like WSAECONNABORTED or something.

        led mike

        1 Reply Last reply
        0
        • M Mike Doner

          Hi all... I'm doing some development which queries a PC network by making requests to a file on the host system through HTTP. I'm experimenting with CInternetSession & CHttpFile, and some of the examples of each on this site. I have a few questions/problems: 1) Is there a way I can easily determine the MAC address of the PC I'm connectedly to? 2) I'm encountering lock-up when the hardware becomes disconnected from the network midway through the CHttpFile->Read() operation. This function hangs infinitely. Is there a timeout you can set for this? I countered this problem with the WebGrab Example Here is a snippet: BOOL CWebGrab::GetFile ( LPCTSTR szURL, CString& strBuffer, LPCTSTR szAgentName /*=NULL*/, CWnd* pWnd /*=NULL*/ ) { // TRACE1("URL is %s\n", szURL); m_rawHeaders =""; m_infoStatusCode=0; strBuffer.Empty(); if (!m_pSession && !Initialise(szAgentName, pWnd)) return FALSE; if (pWnd) m_pSession->SetStatusWnd(pWnd); //m_pSession->SetStatus("Downloading file..."); DWORD dwCount = 0; CHttpFile* pFile = NULL; try { pFile = (CHttpFile*) m_pSession->OpenURL(szURL, 1, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE //| INTERNET_OPEN_FLAG_USE_EXISTING_CONNECT | //| INTERNET_FLAG_RELOAD ); } catch (CInternetException* e) { TCHAR szCause[255]; e->GetErrorMessage(szCause, 255); m_pSession->SetStatus(szCause); // e->ReportError(); e->Delete(); delete pFile; pFile = NULL; return FALSE; } COleDateTime startTime = COleDateTime::GetCurrentTime(); LPSTR pBuf = NULL; if (pFile) { pBuf = (LPSTR) ::GlobalAlloc(GMEM_FIXED, BUFFER_SIZE+1); if (!pBuf) { pFile->Close(); delete pFile; return FALSE; } BYTE buffer[BUFFER_SIZE+1]; try { UINT nRead = 0; DWORD size; dwCount = 0; do { **nRead = pFile->Read(buffer, BUFFER_SIZE); - LOCKS HERE waiting for the rest of the bytes.** if (nRead > 0) {

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Mike Doner wrote:

          1. I'm encountering lock-up when the hardware becomes disconnected from the network midway through the CHttpFile->Read() operation. This function hangs infinitely. Is there a timeout you can set for this?

          Have you tried the INTERNET_OPTION_RECEIVE_TIMEOUT option using CInternetSession::SetOption()? *EDIT* Never mind - I see that's what Ravi said :doh:

          "Great job, team. Head back to base for debriefing and cocktails." (Spottswoode "Team America")

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups