Re: HTTP PUT File upload-Delay in InternetWriteFile() function!

Giganews Newsgroups
Subject:Re: HTTP PUT File upload-Delay in InternetWriteFile() function!
Posted by: Volodymyr Shcherbyna (v_scherbi…@online.mvps.org)
Date:Fri, 14 Dec 2007

Measure precise delay in release binary using GetTickCount function blocks
(before uploading and after file has been uploaded) and please provide
results here.

--
Volodymyr
"Nathan" <Nath…@discussions.microsoft.com> wrote in message
news:41C76E6F-B42B-481D-A528-A32E2FB780…@microsoft.com...
> Hello,
> I am using wininet SDK to upload a file using HTTP PUT to a folder in
> Apache
> Tomcat. Truncated code in c++ is as follows:
>      hRequest = HttpOpenRequest (hConnect, pwcsOperation, (wchar_t*)
> cstrRecStoreFilePath, NULL, NULL, NULL,  0, 0);
>      hFile = CreateFile (pwcsUploadFileName, GENERIC_READ,
> FILE_SHARE_READ,
> NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
>
>      ZeroMemory(&BufferIn, sizeof(INTERNET_BUFFERS));      //  Extra
>      BufferIn.dwBufferTotal = GetFileSize (hFile, NULL);
>      BufferIn.dwStructSize = sizeof(INTERNET_BUFFERS);    //  Extra
>
>      InternetSetOption(hRequest, INTERNET_OPTION_SEND_TIMEOUT |
> INTERNET_OPTION_CONNECT_TIMEOUT, &dwTimeout, sizeof(DWORD));
>
>      if(!HttpSendRequestEx( hRequest, &BufferIn, NULL, HSR_INITIATE &
> HSR_ASYNC, 0))
>      {
>
>          InternetGetLastResponseInfoW(&dwError, (wchar_t*) wcsBuffer,
> &dwBufferSize);
>        }
>      DWORD sum = 0;
>      do
>      {
> if  (!(bRead = ReadFile (hFile, pBuffer, sizeof(pBuffer), &dwBytesRead,
> NULL)))
> {
>
>  break;
>
> }
>
> if (!(bRet=InternetWriteFile( hRequest, pBuffer, dwBytesRead,
> &dwBytesWritten)))
> {
>    break;
> }
> sum += dwBytesWritten;
>        }
>      while (sum < BufferIn.dwBufferTotal) ;
>
>        // Close File handle
>      CloseHandle (hFile);
>      if(!HttpEndRequest(hRequest, NULL, HSR_ASYNC, 0))
>      {
> if (hFile)
>
> {
>  CloseHandle (hFile);
>  hFile = NULL;
>
> }
> if (hRequest)
>
> {
>  InternetCloseHandle (hRequest);
>  hRequest = NULL;
>
> }
>        return FALSE;
>
>      }
> // Handle cleanup code
>  }
>
>  catch (...)
>
>  {
>
>  }
>
> The problem I have is that InternetWriteFile function is causing a delay:
> takes more than a second for a file size 10KB. The network connection is
> 100
> MBPS LAN between the machines.
>
> 1. What are the possible reasons for InternetWriteFile delay?
> 2. Is there any permission on the folder that I am missing?
> 3. If it is a HTTP issue, how do we diagnose the delay?
>
> Any suggestions or inputs appreciated.

Replies

In response to

HTTP PUT File upload-Delay in InternetWriteFile() function! posted by nathan on Thu, 13 Dec 2007