CInternetSession Questions.
-
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) {
-
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) {
-
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) {
Mike Doner wrote:
- 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
-
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) {
Mike Doner wrote:
- 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")