Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Mar : a suggestion for TIdSocketHandle.Readable in Indy101.5

www.cryer.info
Managed Newsgroup Archive

a suggestion for TIdSocketHandle.Readable in Indy101.5

Subject:a suggestion for TIdSocketHandle.Readable in Indy101.5
Posted by:"Huang Xiaobin" (hxbtoug..@yahoo.com.cn)
Date:Tue, 7 Mar 2006 23:11:25

The old proc is as follows:

function TIdSocketHandle.Readable(AMSec: Integer = IdTimeoutDefault):
Boolean;

  function CheckIsReadable(AMSec: Integer): Boolean;
  begin
    if HandleAllocated then begin
      Result := Select(AMSec);
    end else begin
      raise EIdConnClosedGracefully.Create(RSConnectionClosedGracefully);
    end;
  end;

begin
  if TIdAntiFreezeBase.ShouldUse then begin
    if AMSec = IdTimeoutInfinite then begin
      repeat
        Result := CheckIsReadable(GAntiFreeze.IdleTimeOut);
      until Result;
      Exit;
    end else if AMSec > GAntiFreeze.IdleTimeOut then begin
      Result := CheckIsReadable(AMSec - GAntiFreeze.IdleTimeOut);
      if Result then begin
        Exit;
      end;
      AMSec := GAntiFreeze.IdleTimeOut;
    end;
  end;
  Result := CheckIsReadable(AMSec);

end;


This proc is a important proc in Indy10.1.5, but i think use the main body
use the following style should be better


  if TIdAntiFreezeBase.ShouldUse then begin
    if AMSec = IdTimeoutInfinite then begin
      repeat
        Result := CheckIsReadable(GAntiFreeze.IdleTimeOut);
        TIdAntiFreezeBase.DoProcess;
      until Result;
      Exit;
    end else if AMSec > GAntiFreeze.IdleTimeOut then begin
      while AMSec>GAntiFreeze.IdleTimeOut do begin
        Result := CheckIsReadable(GAntiFreeze.IdleTimeOut);
        if Result then Exit;
        TIdAntiFreezeBase.DoProcess;
        AMSec := AMSec - GAntiFreeze.IdleTimeOut
      end;
      if AMSec>0 then Result := CheckIsReadable(GAntiFreeze.IdleTimeOut);
   end else
      Result := CheckIsReadable(AMSec);

  end;
  Result := CheckIsReadable(AMSec);


{-------------------------------------------------------------------------------
when AMSec>GAntiFreeze.IdleTimeOut, we invoke CheckIsReadable per
GAntiFreeze.IdleTimeOut,
and between two invokes TIdAntiFreezeBase.DoProcess is used to process
message
-------------------------------------------------------------------------------}

Replies:

www.cryer.info
Managed Newsgroup Archive