TsgcWebTransportSession › Methods › Close
Closes the streams still open on the session and raises its OnClose event.
procedure Close;
Close is a local teardown, not a wire teardown. It closes every stream still open on the session, raising each stream's own OnClose, and then raises the session's OnClose. By the time it returns, StreamCount is 0. It is guarded against repeat calls: the first call marks the session closed, so a second call returns at once and OnClose is never raised twice. The guard is set before any event runs, so calling Close again from inside OnClose is safe.
What it deliberately does not do:
Close is still running and dangle the reference WebTransportConnect handed you;
Use it as a local signal that your application is finished with the session, and hang your own cleanup off OnClose.
To actually end the session, drop the transport underneath it. On the client, call TsgcHTTP3Client.Disconnect or free the client, which tears down the QUIC connection and frees every session and stream it owns. On the server, close the QUIC connection. The session object is owned by the connection's registry either way, so never free it yourself.
Because Close does not free anything, the session and its streams remain valid after it returns. That said, treat a session you have closed as finished and stop writing to it.
.NET difference. On the managed stack the client calls Close for you: a background task watches the CONNECT stream, and when the server drains or drops it, that task removes the session from the registry and calls Close. So on .NET OnClose can fire without you asking, signalling that the peer ended the session. In Delphi and C++Builder nothing calls Close on your behalf, so OnClose fires only when your own code calls it. The teardown itself matches on every stack: Close closes the session's open streams, so StreamCount falls to 0, and it is guarded against repeat calls, so OnClose is raised at most once.
procedure TfrmClient.btnDisconnectClick(Sender: TObject);
begin
tmrPump.Enabled := False;
// Notify our own handler that we are finished with the session.
if Assigned(FSession) then
FSession.Close; // closes its open streams, then raises OnClose
// This is what actually ends the session: dropping the QUIC connection.
FClient.Disconnect;
FSession := nil; // owned by the client, do not free
FStream := nil; // owned by the session, do not free
end;
procedure TfrmClient.OnSessionClose(Sender: TObject);
begin
memoLog.Lines.Add('session closed, releasing application state');
end;