Hello dz,

You can use CloseDelayed. And the safe thing in OnDataAvailable is like
this:

Count := Receive(Buffer, BytesFree);
if Count <= 0 then
   Exit;
// hier you go on doing the rest of the stuff

So if Receive returns -1 or 0 (error or closed) nothing happens. There
is one thing. If you use linemode and there is a partial line receive,
then OnDataAvailable will fire with the part of the received data.

---
Rgds, Wilfried [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
http://www.mestdagh.biz

Wednesday, December 12, 2007, 22:43, [EMAIL PROTECTED] wrote:

> Hello:
>    I'm performing various requests depending on input
> received in the TWSocket.OnDataAvailable event (using
> LineMode=True).  If an invalid string is received, I
> need to close the connection.  However, calling
> WSocket.Close() from within the event will cause
> OnDataAvailable to trigger again.  I traced this to
> the fact that FRcvdCnt is only reset to zero after
> the user event returns, so when TriggerSessionClosed
> is called it thinks there is new data.

> Even if FLineFound is set to True,
> TriggerSessionClosed checks for the FRcvdCnt being
> greater than zero and calls OnDataAvailable again. 
> The other flag it checks is FLineClearData, but this
> seems to *only* be set when the LineLimit has been
> exceeded:

> procedure
> TCustomLineWSocket.TriggerSessionClosed(Error : Word);
> begin
>   FLineReceivedFlag := TRUE;
>   if FRcvdPtr <> nil then begin
>     // *** Perhaps FLineClearData should
>     //     be set by TriggerDataAvailable
>     //     when the FLineFound is true?
>     if FLineMode and (FRcvdCnt > 0) and (not
> FLineClearData) then begin
>       FLineLength     := FRcvdCnt;
>       while FLineMode and (FLineLength > 0) do
>         inherited TriggerDataAvailable(0);
>     end;
>     FreeMem(FRcvdPtr, FRcvBufSize);
>     FRcvdPtr  := nil;
>     FRcvBufSize := 0;
>     FRcvdCnt  := 0;
>   end;
>   inherited TriggerSessionClosed(Error);
> end;

>    I'm not sure I understand why TriggerSessionClosed
> would want to call OnDataAvailable, but I realize
> there may be reasons for this.  However, I think some
> flag should be set immediately after the line is
> found -- before new data arrives -- so that closing
> the connection does not re-enter the event.

>     -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