Forum > Networking and Web Programming
[lNet] LHTTPClient - upload file. Buffer problem.
(1/1)
Dibo:
Hi,
I'm trying to upload file with LHTTPClient. There is no demo in examples, so I'm doing the same way as with LTCPClient in this topic:
http://lazarus.firmos.at/index.php?topic=5146.0
But I have problem with buffer. Above example presents how to send large text, so we can easily offset sended chunk with String[Position] index, but how do this with file buffer? I'm not familiar with streams. This is fragment of my code:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---private { private declarations } FFile: TFileStream; FBuff: Pointer; FBuffReaded, FBuffSended: Integer; const ChunkSize: Longint = 8192; { copy in 8K chunks } procedure TForm1.FormCreate(Sender: TObject);begin FBuff := GetMem(ChunkSize); FBuffReaded := 0; FBuffSended := 0;end; procedure TForm1.FormDestroy(Sender: TObject);begin Freemem(FBuff); FreeThenNil(FFile);end; procedure TForm1.http_clientCanWrite(ASocket: TLHTTPClientSocket; var OutputEof: TWriteBlockStatus);var n: Integer;begin AddLog('Can write: ' + IntToStr(integer(OutputEof))); OutputEof := wsPendingData; repeat // Next chunk if whole sended if (FBuffSended>=FBuffReaded) and (FFile.Position<FFile.Size) then begin FBuffReaded := FFile.Read(FBuff^, ChunkSize); FBuffSended := 0; if (FBuffReaded=0) then Break; end; n := ASocket.Send(FBuff^, FBuffReaded); Inc(FBuffSended, n); // Loop until filled the OS send buffer or sended whole file until (n=0) or ((FBuffSended>=FBuffReaded) and (FFile.Position>=FFile.Size)); if (FBuffSended>=FBuffReaded) and (FFile.Position>=FFile.Size) then OutputEof := wsDone;end; Line 39. How offset buffer (FBuff^) position to FBuffSended? Because in each loop cycle it send buffer from begining. Can I somehow strip first FBuffSended bytes from FBuff?
Regards and sorry for my English
Navigation
[0] Message Index