Nathan
2007-12-14 05:44:00 UTC
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.
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.