TsgcWebTransportSession › Methods › FindStreamById

FindStreamById Method

Returns the stream registered with the given QUIC stream id, or nil when this session has no such stream.

Syntax

function FindStreamById(aStreamId: Int64): TsgcWebTransportStream;

Parameters

NameTypeDescription
aStreamIdInt64The stream id to look for, matched against each stream's StreamId. A negative value returns nil without searching.

Return Value

The TsgcWebTransportStream whose StreamId equals aStreamId, or nil when no stream in this session matches. The stream stays owned by the session.

Remarks

FindStreamById walks the session's stream list and returns the first match. The list is guarded by a critical section, so the call is thread-safe. It searches locally-opened streams (from OpenStream) and peer-opened ones (from AddIncomingStream) alike.

The search is linear, so it costs O(n) in the number of streams the session has registered. Since StreamCount never shrinks in normal operation, a long-lived session that opens many streams will make this progressively slower. If you need a stream on a hot path, hold your own reference rather than looking it up each time.

You rarely need this. The HTTP/3 client and server use it internally to route inbound QUIC data to the right stream. In application code, the stream object is normally already in your hands: OpenStream returned it, OnStream passed it, or Sender in OnData is it. Reach for FindStreamById only when you have an id from somewhere else, such as your own correlation table or a log line.

A closed stream is still findable, because closing does not remove it from the session. Writing to a stream you get back is therefore not proof it is still usable.

.NET difference. The managed version is a dictionary lookup rather than a linear scan, and returns null when there is no match. Also note that on .NET, a locally-opened stream's StreamId is a synthetic counter rather than the real QUIC stream id (see OpenStream), so ids from a packet capture will only match peer-opened streams.

Example


var
  oStream: TsgcWebTransportStream;
begin
  // vStreamId came from our own correlation table, not from a live object
  oStream := oSession.FindStreamById(vStreamId);
  if Assigned(oStream) then
    oStream.WriteData('continuation data')
  else
    memoLog.Lines.Add('stream ' + IntToStr(vStreamId) + ' is not in this session');
end;

Back to Methods