Internet Direct (Indy) Version 9.0.2 Beta
TIdTCPConnection.OpenWriteBuffer
Indicates that the peer connection should use Indy internal buffering.

procedure OpenWriteBuffer(const AThreshhold: Integer);
Parameters
const AThreshhold: Integer = -1
Number of bytes to buffer before flushing data in the write buffer to the peer. Default value is -1.

Description
OpenWriteBuffer is a procedure that is normally used to capture all data being sent to a peer, and to store the data in the Indy internal buffer until a call to CloseWriteBuffer or FlushWriteBuffer. Use OpenWriteBuffer when all data should be sent to the peer at one time.

AThreshold indicates the number of bytes that can accumulate in the Indy write buffer prior to using FlushWriteBuffer. The write buffer threshold is used to provide optimium data transfer without creating massive in memory buffers, or requiring the caller to periodically flush the buffer. When the write buffer size exceeds the threshold value, the connection will send a packet containing buffered data. The default value of AThreshold (-1) indicates that write buffering should be used for the entire write buffer. FlushWriteBuffer may also use a threshold value to determine the data packet size commited to the peer socket connection from the Indy internal buffer.

Use OpenWriteBuffer in a try...except block, like the following:

   OpenWriteBuffer;
   try;
      WriteStream(AStream);
      // Close the write buffer and have Indy now transmit it
      CloseWriteBuffer;
   except
      // Clear what we had buffered, and disable write buffering
      CancelWriteBuffer;
      // Re-raise the exception so it is not masked
      raise;
   end;