procedure TIdIOHandler.DiscardAll;
begin
BeginWork(wmRead);
try
// If data already exists in the buffer, discard it first.
FInputBuffer.Clear;
// RLebeau - don't call Connected() here! ReadBytes() already
// does that internally. Calling Connected() here can cause an
// EIdConnClosedGracefully
exception that breaks the loop
// prematurely and thus leave unread bytes in the InputBuffer.
// Let the loop catch the
exception before exiting...
repeat
try
if ReadFromSource(False) > 0 then begin
FInputBuffer.Clear;
end else begin;
CheckForDisconnect(True, True);
end;
except
on E:
Exception do begin
// RLebeau - ReadFromSource() could have filled the
// InputBuffer with more bytes...
FInputBuffer.Clear;
if E is EIdConnClosedGracefully then begin
Break;
end else begin
raise;
end;
end;
end;
TIdAntiFreezeBase.DoProcess;
until False;
finally
EndWork(wmRead);
end;
end;