c++ - InternetReadFile filling buffer, but returning zero bytes read -


i'm having strange problem whilst trying download file internet inside c++ application written windows compact 2013.

bool www::read(char* buffer, dword buffer_size) {     memset(buffer, 0, buffer_size);     m_dwbytesread = 0;      bool bresult = internetreadfile(m_handle, buffer, buffer_size, &m_dwbytesread);     if (!bresult)     {         dword dwlasterror = getlasterror();         tchar *err;          if (formatmessage(format_message_allocate_buffer | format_message_from_system,             null, dwlasterror,             makelangid(lang_neutral, sublang_default), // default language             (lptstr)&err, 0, null))         {             logmsg(1, (text("internetreadfile failed @ - (%u) %s\r\n"), dwlasterror, err));             localfree(err);         }     }      // fudge     if (m_dwbytesread == 0)     {         dword dwzeros = countzeros(buffer, buffer_size);         if (dwzeros < buffer_size)         {             m_dwbytesread = buffer_size;         }     }     // end of fudge      return bresult; } 

i repeatedly call above function member function follows

dword dwwritten;  while (!(read(buffer, download_buffer_size) && m_dwbytesread == 0)) {     writefile(m_hdownload, buffer, m_dwbytesread, &dwwritten, null);     m_dwactualsize += dwwritten;     ++m_dwchunks;      if (m_dwbytesread > 0)         m_dwinactivity = 0;     else if (++m_dwinactivity > inactivity_limit)         return wds_inactivity; } 

without fudge, function fails first time through, , works correctly on subsequent calls. error on first pass through function call is

internetreadfile failed @ - (112) there not enough space on disk. 

i don't understand why should getting "not enough space on disk" error during read operation. have checked that buffer allocated, , available, , matches expected size. in fact when inspect contents of buffer, find has been filled expected number of bytes, contents of m_dwbytesread variable still set 0.

as can see, have tried code around specific case inspecting contents of buffer see if has been filled, , fudging m_dwbytesread variable, temporary work around me past error, need understand why problem occurring.

the consequences of error (without fudge), data thrown away, , end file missing first block otherwise correct. consequently md5 checks fail, , missing first part of file.

i happen know file larger block size using, fudge work, don't having these horrible workarounds in code when shouldn't needed.

if can shed light upon causing problem, appreciated.

i'm using visual studio 2013 c++ (native windows app, not mfc), target 32-bit , unicode, running on windows compact 2013.

many thanks, andrew

is machine running out of disk space? internetreadfile write disk behind default:

to ensure data retrieved, application must continue call internetreadfile function until function returns true , lpdwnumberofbytesread parameter equals zero. important if requested data written cache, because otherwise cache not updated , file downloaded not committed cache. note caching happens automatically unless original request open data stream set internet_flag_no_cache_write flag.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -