Skip to main content

MuxServer

Struct MuxServer 

Source
pub struct MuxServer<M: RemoteMessage, In: RemoteMessage, Out: RemoteMessage> { /* private fields */ }
Expand description

A muxed server bundling a simplex receiver, a duplex accept server, and the shared shutdown signal that ties them together.

All three components share one underlying listener. Lifecycle:

  • Dropping the MuxServer cancels the shared shutdown and tears down the listener and any in-flight sessions.
  • MuxServer::stop does the same explicitly.
  • MuxServer::split hands out the address, simplex half, duplex half, and a MuxShutdown separately. After splitting, dropping the simplex half, the duplex half, or the MuxShutdown guard cancels the shared shutdown. The address is a plain value and does not own any resources.

The simplex half is a ChannelRx<M> you recv() on; the duplex half is a [DuplexServer<In, Out>] you accept() on. Neither is join()-able — there is no separate per-half task to await.

Implementations§

Source§

impl<M: RemoteMessage, In: RemoteMessage, Out: RemoteMessage> MuxServer<M, In, Out>

Source

pub fn addr(&self) -> &ChannelAddr

The address the muxed listener is bound to.

Source

pub fn simplex_mut(&mut self) -> &mut ChannelRx<M>

Borrow the simplex receiver.

Source

pub fn duplex_mut(&mut self) -> &mut DuplexServer<In, Out>

Borrow the duplex accept server.

Source

pub fn stop(&self, reason: &str)

Cancel the shared shutdown and tear down both halves.

Source

pub fn split( self, ) -> (ChannelAddr, ChannelRx<M>, DuplexServer<In, Out>, MuxShutdown)

Move the bound address, simplex half, duplex half, and a MuxShutdown guard out of this wrapper. After splitting, dropping the simplex half, the duplex half, or the MuxShutdown guard cancels the shared shutdown and tears the rest down. The address is a plain value and does not own any resources.

Source

pub fn serve<SH, DH, DF>( self, simplex_handler: SH, duplex_handler: DH, ) -> MailboxServerHandle
where SH: FnOnce(ChannelRx<M>) -> MailboxServerHandle, DH: FnOnce(DuplexServer<In, Out>, Receiver<bool>) -> DF, DF: Future<Output = ()> + Send + 'static,

Wire up handlers for both halves, spawn a background task that owns the orderly shutdown (duplex drain → simplex pump → listener), and return a MailboxServerHandle. Calling .stop() on the handle drives the drain.

simplex_handler consumes the simplex receiver and produces the simplex pump’s MailboxServerHandle (typically by calling MailboxServer::serve on a forwarder). duplex_handler receives the DuplexServer and a stop signal, and returns the future driving the duplex pump.

Shutdown ordering. On stop, the coordinator awaits duplex_task first so the duplex handler can drive its own internal drain (e.g., the host’s per-connection forwarder pumps stop and drop their AttachSenders, which lets send_connected flush queued outbound naturally as SendLoopError::AppClosed, before the handler’s terminal duplex_server.stop signals listener shutdown and join waits for it). Stopping the simplex pump and listener happens after the duplex drain to avoid cascading cancellation through dispatch_duplex_stream’s select! while the duplex side still has queued sends.

Mirrors MailboxServer::serve’s shape: take the work to do, return a MailboxServerHandle.

Auto Trait Implementations§

§

impl<M, In, Out> Freeze for MuxServer<M, In, Out>

§

impl<M, In, Out> RefUnwindSafe for MuxServer<M, In, Out>

§

impl<M, In, Out> Send for MuxServer<M, In, Out>

§

impl<M, In, Out> Sync for MuxServer<M, In, Out>

§

impl<M, In, Out> Unpin for MuxServer<M, In, Out>

§

impl<M, In, Out> UnsafeUnpin for MuxServer<M, In, Out>

§

impl<M, In, Out> UnwindSafe for MuxServer<M, In, Out>

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> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

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

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

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

§

fn push_quoted<'q, Q, S>(&mut self, _q: Q, s: S)
where Q: QuoteInto<T>, S: Into<Quotable<'q>>,

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 = Infallible

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

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

§

fn vzip(self) -> V

§

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
§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<M> Message for M
where M: Send + Sync + 'static,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,