pub(crate) struct SessionCloser {
inner: Arc<CloserInner>,
}Expand description
Where crate::action::Action::CloseSession lands.
A OnceLock<(u32, Bytes)> plus the session’s CancellationToken, and
deliberately no Transport handles: the transports own the tasks
that own the hooks that reach this, so holding them here would close a
reference cycle. The close itself happens where it already happens, in
run_with_transport, which reads Self::close_args instead of
hard-coding (0, b"proxy session ended").
CloseSession is honoured at every site that returns an Action,
including Site::StreamEnd on both data and control streams: a close is
session-scoped, so no site can be the wrong one for it.
Fields§
§inner: Arc<CloserInner>Implementations§
Source§impl SessionCloser
impl SessionCloser
Sourcepub(crate) fn new(cancel: CancellationToken) -> Self
pub(crate) fn new(cancel: CancellationToken) -> Self
A closer bound to the session’s cancellation token.
Sourcepub(crate) fn request(&self, code: u32, reason: Bytes) -> bool
pub(crate) fn request(&self, code: u32, reason: Bytes) -> bool
Record a close request and cancel the session.
The first request wins and returns true. A later one changes
nothing and returns false — refuse it with
Refusal::SessionAlreadyClosing
rather than letting the second reason overwrite the first.
Sourcepub(crate) fn record(&self, code: u32, reason: Bytes) -> bool
pub(crate) fn record(&self, code: u32, reason: Bytes) -> bool
Record a close request without cancelling the session.
The first request wins and returns true, exactly as
Self::request does; the only difference is that the session
keeps running afterwards.
That difference is the whole reason this exists. A control-plane
close has two steps — fix the code and reason, then give the egress
queues a bounded window to flush — and Self::request cannot
express the first without the second, because it cancels as it
records. A caller that used it would end the session before the
drain it just asked for had begun, and the drain window would be
unobservable.
Nothing else changes: run_with_transport still reads
Self::close_args at teardown, so a session recorded this way
closes with the recorded pair whenever it does close — whether that
is the caller cancelling after its drain, or the peer going away
first.
Sourcepub(crate) fn is_closing(&self) -> bool
pub(crate) fn is_closing(&self) -> bool
Whether a close has been requested.
session.rs reads Self::requested instead, because it wants the
code and the reason as well; this stays as the cheap yes-or-no
predicate for callers that need nothing more.
Sourcepub(crate) fn requested(&self) -> Option<(u32, Bytes, CloseOrigin)>
pub(crate) fn requested(&self) -> Option<(u32, Bytes, CloseOrigin)>
What was requested and by whom, if anything.
The origin rides along rather than being a second accessor because
the two are set together, under one OnceLock, and a caller that
read them in two calls would be writing a race it does not have.
Sourcepub(crate) fn close_args(&self) -> (u32, Bytes)
pub(crate) fn close_args(&self) -> (u32, Bytes)
The (code, reason) to hand Transport::close, falling back to the
pair the proxy has always used.
The origin is deliberately dropped here: it is a fact about this
process, and what goes on the wire is what the peer was told. A
CONNECTION_CLOSE carrying the control plane asked would be this
proxy leaking its own topology into somebody else’s session.
Trait Implementations§
Source§impl Clone for SessionCloser
impl Clone for SessionCloser
Source§fn clone(&self) -> SessionCloser
fn clone(&self) -> SessionCloser
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more