Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

methodtAbstractSocket.SendAll

function SendAll(var aBuf; aCount: Integer; aStallTimeout: Cardinal; aCancel: PBoolean = nil): Integer; overload;
Writes ALL aCount bytes: the remedy the Send contract prescribes, in one place. A partial count sends the rest; a would-block waits on WaitForWrite and retries with the same bytes. Needed wherever the socket does not wait for room itself: every tPosixSocket, and on Windows a tWinSocket that WaitForData has been called on, or that was accepted from a listener that it was called on (WSAEventSelect makes a socket non-blocking, and an accepted socket inherits that mode from the listener). Returns aCount once everything is written, and less when it stops early:
- the socket is gone (Send returned 0);
- aCancel is assigned and aCancel^ became True while waiting for room;
- aStallTimeout ms passed without a single byte being taken (0 = no limit). The socket is CLOSED first: part of the data may already be on the wire, so the stream cannot be continued, and the peer learns it at once. A real send failure raises EstSocketError, as Send does without aErrorCode, and the socket is then already closed. It does NOT serialize writers: a caller that writes from several threads holds its own lock across the call.
function SendAll(var aBuf; aCount: Integer; aStallTimeout: Cardinal; aCancel: PBoolean; aOnStall: TSocketStallProc): Integer; overload;
SendAll, calling aOnStall (when assigned) each time a send finds no room, before it waits for room - then for at most 1 ms at a time, so that aOnStall is called again soon. aOnStall runs on the calling thread, inside SendAll.