Hello, First of all, I would like to thank Ronny for his kind words on private email. (He finds my messages helpful! :) ). After a week of bug hunting I found the problem: I no longer call Abort() if the existing connection's IP/port is different than target's--I just let the component manage it.
Best Regards, SZ ----- Original Message ----- From: "Fastream Technologies" <[EMAIL PROTECTED]> To: "ICS support mailing" <twsocket@elists.org> Sent: Saturday, September 02, 2006 4:52 PM Subject: Re: [twsocket] Need help with HTTP : Hello, : : I have debugged the code to this point: : : : { 26/11/2003: next 2 lines commented out to allow receiving data outside } : { of any request (server push) } : { if FState <> httpWaitingHeader then : Exit; }{ Should never occur ! } : : while FReceiveLen > 0 do begin : I := Pos(#10, FReceiveBuffer); : if I <= 0 then begin : break; // HERE : end; : : This occurs when I reuse the same THttpCli connection, first HEAD then GET. : I call InternalClear() and set the state to httpReady in between. I also : check for any disconnection and abort then. : : I saw in OnDocData, header being in the Buffer variable. And in this code, : there is no header/just data in FReceiveBuffer. I am puzzled and suffer a : headache. ;0( : : Regards, : : SZ : : ----- Original Message ----- : From: "Francois PIETTE" <[EMAIL PROTECTED]> : To: "ICS support mailing" <twsocket@elists.org> : Sent: Saturday, September 02, 2006 11:00 AM : Subject: Re: [twsocket] Need help with HTTP : : ::> The error I get is it sometimes shuts down before all the :: > data is actually pumped. :: Your code fragment is difficult to understand. There are to much noise :: because of features in your program. You'd better build a simplified code. :: :: Anyway, if this can help you, I remind you that OnDataSrnt event doesn't :: mean the data has been sent out to the remote site but that TWSocket has :: emptied his buffer to winsock own buffer. Winsock has still to send data : and :: for for ack. There is no way to know that winsock has completely sent :: everything out and received corresponding ACK, except by closing the :: connection using linger (this will BLOCK the close operation). :: :: -- :: Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html :: -- :: [EMAIL PROTECTED] :: http://www.overbyte.be :: :: :: :: ----- Original Message ----- :: From: "Fastream Technologies" <[EMAIL PROTECTED]> :: To: "ICS support mailing" <twsocket@elists.org> :: Sent: Friday, September 01, 2006 4:14 PM :: Subject: [twsocket] Need help with HTTP :: :: :: > 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 :: :: -- :: 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 : : -- : 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 -- 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