Skip to main content

NetHandle

Struct NetHandle 

Source
pub struct NetHandle { /* private fields */ }
Expand description

Opaque handle to an event bus instance.

This wraps the EventBus along with a Tokio runtime for async operations.

§Lifetime / soundness

The handle storage is intentionally leaked on net_shutdown rather than freed via Box::from_raw. Reasoning: every FFI entry point dereferences the C-side *mut NetHandle to access the atomics that gate shutdown. The previous Dekker-style SeqCst handshake between FfiOpGuard::try_enter (which calls fetch_add on active_ops) and net_shutdown (which loads active_ops then Box::from_raws the handle) was unsound: SeqCst orders the atomic operations only — the non-atomic Box::from_raw could deallocate the storage between shutdown’s load and a concurrent FFI op’s fetch_add, producing a use-after-free on the freed atomic. By never freeing the box, the atomic memory backing the handle is always valid; concurrent FFI ops observe shutting_down=true after shutdown signals it and bail before touching bus/runtime.

bus and runtime are stored in ManuallyDrop so that net_shutdown can take them out (via ptr::read) in order to call bus.shutdown().await. Because shutting_down is set first and shutdown waits for active_ops to drop to zero before reading these fields, no FFI op can be racing the read. If the wait times out, the ptr::read is skipped and both fields are leaked along with the box.

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.

Source§

impl<T> Instrument for T

Source§

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

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

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

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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