Skip to main content

SessionLoopState

Struct SessionLoopState 

Source
pub struct SessionLoopState {
    pub client_to_backend: ClientToBackendBytes,
    pub backend_to_client: BackendToClientBytes,
    pub last_reported_c2b: ClientToBackendBytes,
    pub last_reported_b2c: BackendToClientBytes,
    pub auth_username: Option<String>,
    pub skip_auth_check: bool,
    /* private fields */
}
Expand description

Session loop state for tracking bytes, auth, and metrics

This struct encapsulates all mutable state needed during a session loop, making it easy to pass around and test in isolation.

§Example

let state = SessionLoopState::new(auth_enabled)
    .with_initial_bytes(1000, 500);

Fields§

§client_to_backend: ClientToBackendBytes

Bytes sent from client to backend

§backend_to_client: BackendToClientBytes

Bytes sent from backend to client

§last_reported_c2b: ClientToBackendBytes

Last reported client-to-backend bytes (for incremental metrics)

§last_reported_b2c: BackendToClientBytes

Last reported backend-to-client bytes (for incremental metrics)

§auth_username: Option<String>

Username from AUTHINFO USER command (if any)

§skip_auth_check: bool

Whether to skip auth checking (optimization after first auth)

Implementations§

Source§

impl SessionLoopState

Source

pub fn new(auth_enabled: bool) -> Self

Create new session loop state

§Arguments
  • auth_enabled - If true, auth checking starts enabled; if false, it’s skipped
Source

pub fn from_initial_bytes( client_to_backend: u64, backend_to_client: u64, auth_enabled: bool, ) -> Self

Create session loop state with initial byte counts

Used by hybrid mode when switching from per-command to stateful, to carry forward the bytes already transferred.

Source

pub const fn with_initial_bytes(self, c2b: u64, b2c: u64) -> Self

Builder method: set initial byte counts

Source

pub const fn check_and_maybe_flush_metrics(&mut self) -> bool

Check if metrics should be flushed and reset counter if so

Returns true every METRICS_FLUSH_INTERVAL iterations.

Source

pub const fn add_client_to_backend(&mut self, bytes: usize)

Add bytes to client-to-backend counter

Source

pub const fn add_backend_to_client(&mut self, bytes: u64)

Add bytes to backend-to-client counter

Source

pub fn flush_byte_deltas( &mut self, metrics: &MetricsCollector, backend_id: BackendId, username: Option<&str>, )

Flush accumulated byte deltas to the metrics collector.

Reports the difference since the last flush and updates the last-reported watermarks. Used by both the periodic in-loop flush and the final flush on disconnect.

Source

pub fn into_metrics(self) -> TransferMetrics

Convert to final transfer metrics

Source

pub fn mark_authenticated(&mut self)

Mark authentication as complete (skip future checks)

Source

pub fn apply_auth_result(&mut self, result: &AuthHandlerResult) -> u64

Update state based on auth handler result

Returns the bytes written for convenience in chaining.

Source

pub fn mark_backend_request_sent(&mut self, kind: RequestKind)

Mark that a backend request was forwarded and its reply must be ordered first.

Source

pub fn has_pending_backend_replies(&self) -> bool

Whether earlier forwarded backend replies are still ahead of any deferred local replies.

Source

pub fn push_deferred_reply(&mut self, reply: &'static [u8])

Queue a local reply until earlier backend output has been sent.

Source

pub fn has_deferred_replies(&self) -> bool

Whether deferred local replies remain queued.

Source

pub fn read_mode(&self) -> StatefulReadMode

Reading mode for the stateful loop.

Source

pub fn take_ready_deferred_replies(&mut self) -> SmallVec<[&'static [u8]; 2]>

Drain deferred local replies that are ready at the front of the ordered queue.

Trait Implementations§

Source§

impl Default for SessionLoopState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scope for T

Source§

fn with<F, R>(self, f: F) -> R
where Self: Sized, F: FnOnce(Self) -> R,

Scoped with ownership.
Source§

fn with_ref<F, R>(&self, f: F) -> R
where F: FnOnce(&Self) -> R,

Scoped with reference.
Source§

fn with_mut<F, R>(&mut self, f: F) -> R
where F: FnOnce(&mut Self) -> R,

Scoped with mutable reference.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Value for T
where T: Send + Sync + 'static,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more