On Mar 29, 2010, at 03:39, Jon Robertson wrote:

> I should have only included FRvcdCnt := 0;  That will prevent
> TriggerSessionClosed from calling TriggerDataAvailable, and allow
> TCustomLineWSocket.Destroy to free the buffer, rather than having multiple
> code snippets that free the buffer, which could lead to a bug later if all
> of the code snippets are not kept in sync when something changes.

No, you must do the same thing that TriggerSessionClosed() does and free the 
buffer.  You shouldn't wait for the destruction of the component to do this.

    // In TCustomLineWSocket:
    procedure   InternalAbort(ErrCode : Word); override;
    // ...

procedure TCustomLineWSocket.InternalAbort(ErrCode : Word);
begin
    // Destroy the line buffer
    if (FRcvdPtr <> nil) then begin
        {$IFDEF CLR}
        SetLength(FRcvdPtr, FRcvBufSize);
        {$ENDIF}
        {$IFDEF WIN32}
        FreeMem(FRcvdPtr, FRcvBufSize);
        FRcvdPtr    := nil;
        {$ENDIF}
        FRcvBufSize := 0;
        FRcvdCnt    := 0;
    end;

    inherited InternalAbort(ErrCode);
end


TriggerSessionClosed() was going to do it anyway, but by doing it in Abort() 
you avoid the call to TriggerDataAvailable.

It is really so simple.  It never occurred to me that there is absolutely no 
reason to read the buffer after Abort, so destroying to buffer is the best 
solution.

Thanks Arno and Francois!

        dZ.
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to