TsgcWebTransportSession › Properties › StreamCount

StreamCount Property

Number of TsgcWebTransportStream objects currently open on this session.

Syntax

property StreamCount: Integer read GetStreamCount;

Type

Integer (int in C++Builder and C#).

Default

0 for a newly created session, before any stream is opened.

Remarks

Read-only. StreamCount returns the size of the session's internal list of open streams. A stream joins that list when OpenStream creates it locally, or when AddIncomingStream registers one the peer opened.

It is a live gauge of open streams. Calling Close on a stream unregisters it from the session before raising its OnClose event, so StreamCount drops as soon as the stream closes. Closing the session with Close closes every stream still open on it, so StreamCount falls to 0. You do not need to call RemoveStream yourself, a stream's Close already does it.

Read it whenever you need to know how many streams the session is carrying right now, for diagnostics or to spot a runaway peer. A closed stream object stays alive until the session is destroyed, so any reference you kept to it remains valid, but it is no longer counted here.

Reading StreamCount is thread-safe: the stream list is guarded by a critical section.

Example


procedure TfrmServer.OnWTStream(Sender: TObject;
  const aStream: TsgcWebTransportStream);
var
  oSession: TsgcWebTransportSession;
begin
  oSession := aStream.Session;
  memoLog.Lines.Add(Format('stream %d registered, session now holds %d',
    [aStream.StreamId, oSession.StreamCount]));

  // A crude guard against a peer that opens streams without limit.
  if oSession.StreamCount > 1000 then
    oSession.Close;

  aStream.OnData := OnWTStreamData;
end;

Back to Properties