Skip to main content

UdpManager

Struct UdpManager 

Source
pub struct UdpManager<E: FlowKeyExtractor = SourceTupleExtractor> { /* private fields */ }
Expand description

The pure UDP flow manager. Generic over the flow-key extractor so the seam stays type-checked; the shell instantiates it with SourceTupleExtractor.

Implementations§

Source§

impl UdpManager<SourceTupleExtractor>

Source

pub fn new( cluster: ClusterConfig, max_flows: usize, max_rx_datagram_size: usize, hash_seed: u64, ) -> Self

Construct a manager with the default client source-address extractor.

Source§

impl<E: FlowKeyExtractor> UdpManager<E>

Source

pub fn with_extractor( cluster: ClusterConfig, max_flows: usize, max_rx_datagram_size: usize, hash_seed: u64, extractor: E, ) -> Self

Construct a manager with a custom flow-key extractor.

Source

pub fn flow_count(&self) -> usize

Number of currently admitted flows. Mirrors udp.active_flows.

Source

pub fn max_flows(&self) -> usize

The configured flow-table cap.

Source

pub fn cluster_config(&self) -> &ClusterConfig

The cluster routing + per-cluster knobs new flows are admitted under.

Source

pub fn is_draining(&self) -> bool

Whether the listener is draining.

Source

pub fn flow(&self, flow: FlowId) -> Option<&UdpFlow>

Borrow a flow by id (for the shell’s access log on close).

Source

pub fn handle_input(&mut self, input: ManagerInput<'_>, now: Instant)

Feed one input into the manager. Pure: now is injected.

Source

pub fn abort_flow(&mut self, flow: FlowId, _now: Instant, reason: CloseReason)

Tear down a single flow on demand, emitting the same outputs a normal idle close produces — Output::Metric(MetricEvent::FlowEvicted) then Output::CloseFlow(flow) — so the shell draining poll_output() decrements udp.active_flows and frees the upstream socket exactly once.

The shell calls this when it cannot establish a flow it just admitted: the upstream connect() failed (EMFILE / connection refused) or no backend resolved. Without it the flow would sit AwaitingBackend / Established pinning a max_flows slot for the full idle timeout.

Idempotent: a missing flow or one already Closing is a no-op — no double-evict, no gauge underflow. Works in either AwaitingBackend or Established. now is accepted for signature symmetry with the other time-driven entry points (the teardown itself is time-independent).

Source

pub fn close_all(&mut self, now: Instant)

Tear down EVERY live flow, emitting — for each — the same outputs a normal idle close produces (Output::Metric(MetricEvent::FlowEvicted) then Output::CloseFlow(flow)), so the shell draining poll_output() decrements udp.active_flows and frees each upstream socket exactly once per flow.

The shell calls this on listener remove / deactivate / soft-stop before dropping the manager, so the active-flows gauge does not leak. Draining the flow table + slab to zero; a flow already Closing is skipped (idempotent, no double-evict, no underflow). After this returns, flow_count() == 0 and no timer is armed.

Source

pub fn handle_timeout(&mut self, now: Instant)

Fire all flows whose idle deadline has elapsed at now. Deadline revalidation: a flow is selected, and re-checked before its close, by idle_deadline <= now alone. A flow that saw traffic since the expiry was armed has a later idle_deadline, so the stale expiry leaves it open; UdpFlow::timer_gen is not consulted.

Called ONLY from a wheel expiry: the shell’s single timer entry has just been delivered and consumed. now is therefore the wheel’s tick date, not the deadline — crate::timer rounds a delay to the nearest tick, so with a 100 ms tick the entry arrives up to 50 ms EARLY on the tick grid (up to 99 ms off it; see duration_to_tick) and no flow need be due at all. Either way the shell now holds nothing, so armed_deadline is cleared on entry and reschedule re-emits ArmTimer even when the minimum deadline has not moved. Without that, an early expiry is a LOST WAKEUP: nothing is closed, nothing is re-armed, and the flow is never reaped until some other flow’s deadline happens to change the minimum. This is the consume-then-reschedule rule, and its cost is one extra wheel wakeup per early-fired expiry.

Source

pub fn poll_timeout(&self) -> Option<Instant>

The next manager-wide deadline, or None if no flow is armed. After a Self::handle_timeout at deadline d, the value returned here is guaranteed > d (or None) — the strict-advance invariant handle_timeout asserts in debug builds, which is what stops the shell busy-looping.

Source

pub fn poll_output(&mut self) -> Option<Output>

Drain the next queued output, or None when the queue is empty.

Auto Trait Implementations§

§

impl<E> Freeze for UdpManager<E>
where E: Freeze,

§

impl<E> RefUnwindSafe for UdpManager<E>
where E: RefUnwindSafe,

§

impl<E> Send for UdpManager<E>
where E: Send,

§

impl<E> Sync for UdpManager<E>
where E: Sync,

§

impl<E> Unpin for UdpManager<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for UdpManager<E>
where E: UnsafeUnpin,

§

impl<E> UnwindSafe for UdpManager<E>
where E: UnwindSafe,

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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, 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> Same for T

Source§

type Output = T

Should always be Self
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.