Hello,
In the OnDocData of THttpCli descendent, I pause the THTtpCli and
Send(Buffer, Len) to the THttpConnection (this is a proxy server). The
problem is at ConnectionDataAvailable of THttpConnection, I cannot be sure
that all the data is sent or is it complete because sometimes packets are
merged and I cannot be sure how much of the downloaded data is actually sent
to the client. Here is the code:
void __fastcall httpServerClientClass::HTTPClientDocData(TObject *Sender,
Pointer Buffer,
int Len)
{
if(compressionType <= 0 && !absURLTranslation && (!noContentLength ||
transferEncodingChunked))
{
HTTPClient->PauseCS(false);
sendDataToRequesterClient(Buffer, Len);
}
else
{
aggregateDataForGZipSending(Buffer, Len);
}
}
//---------------------------------------------------------------------------
void __fastcall httpServerClientClass::sendDataToRequesterClient(Pointer
buffer, int len)
{
if(cacheType == cacheJustAdd)
{
lockCriticalSection(objectCacheCS);
objectCache->Position = cachePosition;
objectCache->Write(buffer, len);
cachePosition = objectCache->Position;
releaseCriticalSection(objectCacheCS);
}
int Count = 0;
if(transferEncodingChunked && State == wsConnected && lastCommand !=
httpCommandHEAD && protocolStatus[1] != '3')
{
Count = SendStr("\r\n" + String(IntToHex(len, 1)) + "\r\n");
bytesReceived += Count;
}
if(State == wsConnected)
{
Count += Send(buffer, len);
DataSent += Count; // count data which is sent by the last buffer
if(transferEncodingChunked && DataSent >= DataToBeSent)
{
if(protocolStatus[1] != '3' && lastCommand != httpCommandHEAD)
{
SendStr("\r\n0\r\n\r\n");
bytesReceived += 7;
}
}
countTransferredPer100ms(Count);
setLastActionTime();
}
}
//---------------------------------------------------------------------------
void __fastcall httpServerClientClass::HTTPClientDocEnd(TObject *Sender)
{
if(HTTPClient)
HTTPClient->setState(httpReady);
if(noContentLength || transferEncodingChunked)
if(cacheType == cacheJustAdd)
cache->setActualFileSize(cacheURL);
if(compressionType > 0 || absURLTranslation || (noContentLength &&
!transferEncodingChunked))
SendDocumentWGZip();
else
{
if(transferEncodingChunked)
chunkedTransferEnded = true;
}
}
//---------------------------------------------------------------------------
void __fastcall
httpServerClientClass::ConnectionDataSentCleartextTunnel(TObject *Sender,
WORD Error)
{
++bytesSent;
if(
(
(!transferEncodingChunked && DataSent >= DataToBeSent && DataPrevSent ==
DataSent)
||
(transferEncodingChunked && chunkedTransferEnded)
)
||
Error
||
(lastCommand == httpCommandHEAD || protocolStatus[1] == '3')
)
{
objectPosition = DataSent;
socketError = Error;
endOfResponse();
if(!FKeepAlive || Error)
Shutdown(1);
return;
}
if(HTTPClient)
HTTPClient->ResumeCSIfNotPausedByThrottler();
}
The error I get is it sometimes shuts down before all the data is actually
pumped.
Hope you can help.
Best Regards,
SZ
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be