Q: How to wait for and read all data available from a Indy TCP socket? I write a Indy TCP server / client application to transfer files. It seems that every call to a read or write operation on a TCP socket, in Indy, slows the transfer speed... I thinked a protocol with only a write and a read (replay). But, in this way, I cannot send the length of the buffer. So, I need to read all available data from the other side, in a continuously buffer. And this operation should wait first, if no data available. Is this possible ? I think it's something with the ReadFromSource method, but this is not documented in the help, and I don't know where it puts the readed data.
My protocol is made in a TIdIOHandlerStack descendant, so I can access protected IOHandler methods.
Edit: It seems that ReadFromSource gets only 32 KB in on shoot. I updated the RecvBufferSize to 2.1MB and when I send 2MB I get about 200 KB... :(
Update: This is the code I use to read all data from the source. Sometimes it works, but other times doesn't read the whole data...
function TIdEnhancedIOHandler.ReadAllBytes(var VBuffer: TIdBytes): Integer;
var LBytes, TmOut: Integer;
begin
 Result:= 0;
 Assert(FInputBuffer <> nil);
 if FInputBuffer.Size = 0 then TmOut:= -1 else TmOut:= 0;
 repeat
  LBytes:= ReadFromSource(False, TmOut, False);
  CheckForDisconnect(True, True);
  TmOut:= 0;
 until LBytes <= 0;
 Result:= FInputBuffer.Size;
 FInputBuffer.ExtractToBytes(VBuffer, -1, False);
end;

