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