Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Mar : Bug fix for Indy10.1.5(TIdEcho)

www.cryer.info
Managed Newsgroup Archive

Bug fix for Indy10.1.5(TIdEcho)

Subject:Bug fix for Indy10.1.5(TIdEcho)
Posted by:"Huang Xiaobin" (hxbtoug..@yahoo.com.cn)
Date:Tue, 7 Mar 2006 22:55:54

The Old Proc:

function TIdEcho.Echo(AText: String): String;
var
  StartTime: Cardinal;
begin
  {Send time monitoring}
  BeginWork(wmWrite, Length(AText)+2);
  try
    StartTime := IdGlobal.Ticks;
    IOHandler.Write(AText);
  finally
    EndWork(wmWrite);
  end;
  {Receive time monitoring}
  BeginWork(wmRead);
  try
    IOHandler.CheckForDataOnSource;
    Result := IOHandler.InputBufferAsString;
    //CurrentReadBuffer;
    {This is just in case the TickCount rolled back to zero}
    FEchoTime :=  GetTickDiff(StartTime,Ticks);

  finally
    EndWork(wmRead);
  end;
end;

Should be corrected as:

function TIdEcho.Echo(AText: String): String;
var
  StartTime: Cardinal;
begin
  Connect;
  try
    {Send time monitoring}
    BeginWork(wmWrite, Length(AText)+2);
    try
      StartTime := IdGlobal.Ticks;
      IOHandler.Write(AText);
    finally
      EndWork(wmWrite);
    end;

    {Receive time monitoring}
    BeginWork(wmRead);
    try
      IOHandler.CheckForDataOnSource(FReadTimeout);
      Result := IOHandler.InputBufferAsString;
      //CurrentReadBuffer;
      {This is just in case the TickCount rolled back to zero}
      FEchoTime := GetTickDiff(StartTime,Ticks);
    finally
      EndWork(wmRead);
    end;
  finally
    Disconnect;
  end;
end;

notes:

(1) the old procedure forget to connect, so the IOHandler is nil, it will
trigger exception.
in the fixed procedure, we first connect the host, and at finally section
disconnect the host.

(2) the old procedure use CheckForDataOnSource to check the data, and it
will invoke readable proc,
but if we did not import parameter to the CheckForDataOnSource, the readable
proc will be invoked
like readabble(0), so the data will be never detected. We use the
FReadTimeout as the input parameter,
!!!yet you must note that the ReadTimeout property is not published in
TIdEcho component, then you should
write code(ie IdEcho.ReadTimeout:=5000) before invoke IdEcho1.Echo
function.!!!

Replies:

www.cryer.info
Managed Newsgroup Archive