Re: Impovement suggestion

Giganews Newsgroups
Subject: Re: Impovement suggestion
Posted by:  Remy Lebeau (Indy Team) (no.spam@no.spam.com)
Date: Mon, 18 Sep 2006

"Igor Panchenko" <ig…@implabs.com> wrote in message
news:op.tf2i8ge3dp6g9t@cab213sys...

> I suggest to change IdGlobal.Sleep(LSleepTime) to
> WaitForSingleObject(Handle, LSleepTime)
> and add Windows to the uses clause.

That is not going to happen.  Indy is cross-platform.  The code has to
compile for Windows, Linux, .NET, and FreePascal, without litering {$IFDEF}
statements all over the place.  WaitForSingleObject() is a Windows-specific
function.  It will not be usable in that section of code.  The Sleep()
function in the IdGlobal unit is implemented in a cross-platform manner.
Besides, Indy 9 is feature-frozen anyway since Indy 10 is the active version
now, so Indy 9 will not be changed anymore except for critical bug fixes,
which this is not.

If you are that concerned about sleeping before checking whether the thread
has been terminated, then simply remove that particular Sleep() until after
the state has been checked.  For example:

    procedure DoConnectTimeout(ATimeout: Integer);
    var
        LSleepTime: Integer;
    begin
        if ATimeout = IdTimeoutDefault then begin
            ATimeout := IdTimeoutInfinite;
        end;

        with TIdConnectThread.Create(True) do
        try
            FBinding := Binding;
            Resume;

            // set up Sleep interval
            if TIdAntiFreezeBase.ShouldUse then begin
                LSleepTime := Min(GAntiFreeze.IdleTimeOut, 25);
            end else begin
                LSleepTime := 25;
            end;

            if ATimeout = IdTimeoutInfinite then
            begin
                while not Terminated do
                begin
                    IdGlobal.Sleep(LSleepTime);
                    TIdAntiFreezeBase.DoProcess;
                end;
            end else
            begin
                while ATimeout > LSleepTime do
                begin
                    if Terminated then
                    begin
                        ATimeout := 0;
                        Break;
                    end;
                    IdGlobal.Sleep(LSleepTime);
                    Dec(ATimeout, LSleepTime);
                    TIdAntiFreezeBase.DoProcess;
                end;
                IdGlobal.Sleep(ATimeout);
            end;

            //...

        finally
            Free;
        end;
    end;

Gambit

Replies

In response to

Impovement suggestion posted by Igor Panchenko on Mon, 18 Sep 2006