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
MuxServercancels the shared shutdown and tears down the listener and any in-flight sessions. MuxServer::stopdoes the same explicitly.MuxServer::splithands out the address, simplex half, duplex half, and aMuxShutdownseparately. After splitting, dropping the simplex half, the duplex half, or theMuxShutdownguard 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>
impl<M: RemoteMessage, In: RemoteMessage, Out: RemoteMessage> MuxServer<M, In, Out>
Sourcepub fn addr(&self) -> &ChannelAddr
pub fn addr(&self) -> &ChannelAddr
The address the muxed listener is bound to.
Sourcepub fn simplex_mut(&mut self) -> &mut ChannelRx<M>
pub fn simplex_mut(&mut self) -> &mut ChannelRx<M>
Borrow the simplex receiver.
Sourcepub fn duplex_mut(&mut self) -> &mut DuplexServer<In, Out>
pub fn duplex_mut(&mut self) -> &mut DuplexServer<In, Out>
Borrow the duplex accept server.
Sourcepub fn split(
self,
) -> (ChannelAddr, ChannelRx<M>, DuplexServer<In, Out>, MuxShutdown)
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.
Sourcepub 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,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].