methodtAbstractSocket.ConnectionEnded
function ConnectionEnded(aErrorCode: PInteger = nil): Boolean; virtual;
True when the connection has ENDED, as far as that can be seen without waiting and without taking any data:
- the peer has closed its end (FIN) and every byte it sent before has been read;
- the connection has failed - reset by the peer, or aborted by this end's stack, which on Windows also discards what had arrived and not been read yet;
- the socket is closed. False while the connection is up, and while anything is waiting to be read - also data that ReceiveLength does not count. On a listening socket it is always False. It is for a reader that polls ReceiveLength instead of waiting in Receive: such a reader never sees the 0 or the error that Receive would report, and without this polls a dead connection for ever. With aErrorCode assigned, a failure stores its error code there (nothing is stored for a FIN). The socket is NOT closed; the caller closes it, as after a Receive that returned 0. It costs a system call or two, so a reader that polls often should not ask on every poll. It takes the socket's lock, as Receive and Send do, so it waits for one of those in progress on another thread. The base class answers only the last case (not Connected); both platform classes answer all three.