Skip to main content

ShapeControl

Struct ShapeControl 

Source
pub(crate) struct ShapeControl {
    profile: Mutex<Option<ShapeProfile>>,
    generation: AtomicU64,
    enabled: Arc<AtomicBool>,
}
Expand description

This proxy’s shaping profile, and whether it paces.

One per proxy, watched by every session it accepts. The generation is what lets a session notice a change without comparing profiles: a session caches the generation its scheduler was built at, and a mismatch is the signal to look.

Fields§

§profile: Mutex<Option<ShapeProfile>>

The profile a live request installed, or None while the proxy’s own template is what every session shapes with.

§generation: AtomicU64

Bumped, under the lock above, every time the profile is replaced.

§enabled: Arc<AtomicBool>

Whether the schedulers built from this pace at all. Behind its own Arc because every scheduler holds a clone of it.

Implementations§

Source§

impl ShapeControl

Source

fn new() -> Self

A control with no profile of its own and pacing switched on, which is the state that leaves a proxy behaving exactly as its configuration says.

Source

fn set(&self, profile: ShapeProfile)

Replace the profile and move the generation on.

Source

pub(crate) fn generation(&self) -> u64

The current generation, without cloning a profile.

What a session checks per stream; the clone below is paid only when this has moved.

Source

pub(crate) fn snapshot(&self) -> (u64, Option<ShapeProfile>)

The generation and the profile it names, read together.

Read under the lock the setter writes under, so the pair cannot straddle two calls to Self::set — a session that cached a generation from one profile and a profile from another would stop noticing the newer of the two.

Source

pub(crate) fn switch(&self) -> Arc<AtomicBool>

The switch every scheduler built from this reads.

Source

fn set_enabled(&self, on: bool)

Turn pacing on or off for every session at once.

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.

§

impl<T> Instrument for T

§

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

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

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, 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, !>

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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