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

TCustomLineWSocket.TriggerSessionClosed(Error : Word);
  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);
    FreeMem(FRcvdPtr, FRcvBufSize);
    FRcvdPtr  := nil;
    FRcvBufSize := 0;
    FRcvdCnt  := 0;
  inherited TriggerSessionClosed(Error);

   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.


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