GetResponse/GetInternalResponse/ReadLnWait endless loop bug

Giganews Newsgroups
Subject: GetResponse/GetInternalResponse/ReadLnWait endless loop bug
Posted by:  Samuel Soldat (samuel.sold…@snafu.de)
Date: Sat, 25 Aug 2007

Dear Sirs,

why do you not add the fix for the wellknown and often reported bug in  =

ReadLnWait? This bug will result in a endless loop in the case of timeou=
t  =

during ReadLn. This will cause hang some components like TIdFTP. As  =

suggest of a lot of people here the fix for that (from Chad Z. Hower - t=
hx  =

for that):

unit IdIOHandler;
....
type
  ...
  EIdIoHandlerReadLnWaitFailedAttempts =3D class(EIdIoHandler);
  ...

function TIdIOHandler.ReadLnWait(AFailCount: Integer =3D MaxInt; const  =

AEncoding: TIdEncoding =3D en7Bit): string;
var
  LAttempts: Integer;
begin
// MtW: this is mostly used when empty lines could be send.
  Result :=3D '';
  LAttempts :=3D 0;
  while ((Length(Result) =3D 0) and (LAttempts < AFailCount)) do
  begin
    Inc(LAttempts);
    Result :=3D Trim(ReadLn);
    EIdReadTimeout.IfTrue(ReadLnTimedOut, RSReadTimeout); //Avoid endle=
ss  =

loop in the case of ReadLnTimedOut
  end;
  EIdIoHandlerReadLnWaitFailedAttempts.IfTrue(Length(Result) =3D 0,  =

RSFailedLineAttempts);
end;
....
end.

I add this fix for me in every new development snapshot and over the yea=
rs  =

it is very boring.

-- =

Samuel Soldat

Replies