pub struct Subscription { /* private fields */ }Expand description
Represents a registered subscription stored inside a context.
Implementations§
Source§impl Subscription
impl Subscription
Sourcepub fn new(
id: SubscriptionId,
config: SubscriptionConfig,
socket: Socket,
) -> Self
pub fn new( id: SubscriptionId, config: SubscriptionConfig, socket: Socket, ) -> Self
Creates a new subscription from an ID, configuration, and socket.
This is a low-level constructor. Callers are responsible for providing a
socket that is compatible with the subscription configuration. For the
checked convenience path, prefer Context::add_subscription_with_socket().
Sourcepub fn id(&self) -> SubscriptionId
pub fn id(&self) -> SubscriptionId
Returns the subscription’s ID.
Sourcepub fn config(&self) -> &SubscriptionConfig
pub fn config(&self) -> &SubscriptionConfig
Returns a read-only reference to the subscription’s configuration.
Sourcepub fn socket_mut(&mut self) -> &mut Socket ⓘ
pub fn socket_mut(&mut self) -> &mut Socket ⓘ
Returns a mutable reference to the subscription’s socket.
This is useful when an external event loop or registry needs mutable socket access during registration.
Sourcepub fn try_recv(&self) -> Result<Option<Packet>, McrxError>
pub fn try_recv(&self) -> Result<Option<Packet>, McrxError>
Attempts to receive a single packet without blocking.
Returns:
Ok(Some(packet))if a packet was received,Ok(None)if no packet is currently available,Err(...)on an actual receive failure.
Sourcepub fn try_recv_with_metadata(
&self,
) -> Result<Option<PacketWithMetadata>, McrxError>
pub fn try_recv_with_metadata( &self, ) -> Result<Option<PacketWithMetadata>, McrxError>
Attempts to receive a single packet together with richer receive metadata without blocking.
Sourcepub fn as_raw_fd(&self) -> RawFd
pub fn as_raw_fd(&self) -> RawFd
Returns the raw Unix file descriptor of the underlying socket.
This is useful for integrating subscriptions into external event loops.
Sourcepub fn local_addr(&self) -> Result<SocketAddr, McrxError>
pub fn local_addr(&self) -> Result<SocketAddr, McrxError>
Returns the local socket address currently bound by this subscription.
Sourcepub fn into_socket(self) -> Socket ⓘ
pub fn into_socket(self) -> Socket ⓘ
Consumes the subscription and returns its owned socket.
This is useful when handing a joined or bound socket off to an external event loop or async runtime.
Sourcepub fn into_parts(self) -> SubscriptionParts
pub fn into_parts(self) -> SubscriptionParts
Consumes the subscription and returns all owned parts.
Sourcepub fn state(&self) -> SubscriptionState
pub fn state(&self) -> SubscriptionState
Returns the current lifecycle state of the subscription.
This can be used by callers to inspect whether the subscription is currently joined to its multicast group or only bound.
Sourcepub fn is_joined(&self) -> bool
pub fn is_joined(&self) -> bool
Returns true if the subscription is currently joined to its multicast group.
This is a convenience helper for checking whether the subscription is in
the SubscriptionState::Joined state.
Sourcepub fn mark_joined(&mut self) -> Result<(), McrxError>
pub fn mark_joined(&mut self) -> Result<(), McrxError>
Marks the subscription as joined.
This should be called after a successful multicast join operation on the underlying socket.
Returns an error if the subscription is already in the joined state.
Sourcepub fn mark_bound(&mut self) -> Result<(), McrxError>
pub fn mark_bound(&mut self) -> Result<(), McrxError>
Marks the subscription as bound (not joined).
This should be called after leaving a multicast group, while keeping the underlying socket open and bound.
Returns an error if the subscription is already in the bound state.