pub struct Net { /* private fields */ }Expand description
The single public API facade exposed by net-kit.
Net itself is only responsible for lifecycle management and forwarding;
all of the actual runtime and network-monitoring logic lives in the
internal [InnerNet], ensuring isolation.
Implementations§
Source§impl Net
impl Net
Sourcepub async fn start(&self) -> Result<(), NetError>
pub async fn start(&self) -> Result<(), NetError>
Start network monitoring. Redundant calls are ignored; start may be
called again after shutdown.
Internally creates and owns a runtime engine owned by net-kit.
Sourcepub async fn start_with_tokio_rt(
&self,
runtime_handle: Handle,
) -> Result<(), NetError>
pub async fn start_with_tokio_rt( &self, runtime_handle: Handle, ) -> Result<(), NetError>
Start network monitoring. Redundant calls are ignored; start may be
called again after shutdown.
Uses a Tokio runtime supplied by the developer. The caller is
responsible for keeping that runtime alive; shutdown does not close
it.
Sourcepub fn shutdown(&self) -> Result<(), NetError>
pub fn shutdown(&self) -> Result<(), NetError>
Stop network monitoring and destroy all resources created by start.
Redundant calls are ignored.
Sourcepub fn local_network_reachability(&self) -> Result<NetworkStatus, NetError>
pub fn local_network_reachability(&self) -> Result<NetworkStatus, NetError>
Query whether the network is currently available.
Returns NetworkStatus::Unavailable when not started; returns
NetError::Lock if an internal lock is poisoned, leaving recovery to
the developer.
Sourcepub fn register(
&self,
listener: NetworkStatusListener,
) -> Result<Option<NetworkStatusListenerHandle>, NetError>
pub fn register( &self, listener: NetworkStatusListener, ) -> Result<Option<NetworkStatusListenerHandle>, NetError>
Register a network notification listener; multiple may be registered.
Returns Ok(None) when not started; Ok(Some(handle)) on success after
start; returns NetError::Lock if an internal lock is poisoned.
Sourcepub fn unregister(
&self,
handle: NetworkStatusListenerHandle,
) -> Result<bool, NetError>
pub fn unregister( &self, handle: NetworkStatusListenerHandle, ) -> Result<bool, NetError>
Unregister a network notification listener by handle.
Returns Ok(false) when not started; Ok(true) when a listener was
found and removed; returns NetError::Lock if an internal lock is
poisoned.
Sourcepub fn clear_all_listener(&self) -> Result<(), NetError>
pub fn clear_all_listener(&self) -> Result<(), NetError>
Clear all registered network listeners. Returns NetError::NotStarted
when not started.
Sourcepub fn is_started(&self) -> bool
pub fn is_started(&self) -> bool
Query whether network monitoring is currently started.
Returns true while an engine is installed (i.e. after start and
before shutdown); returns false otherwise. A poisoned internal lock
is treated as not started, so this method never panics and never returns
an error.
Sourcepub fn is_shutdown(&self) -> bool
pub fn is_shutdown(&self) -> bool
Query whether network monitoring is currently shut down (i.e. not started).
This is the logical inverse of Net::is_started: it returns true
before the first start and after every shutdown. A poisoned internal
lock is treated as not started, so this method never panics and never
returns an error.
Sourcepub fn get_current_network_name(&self) -> Result<Option<String>, NetError>
pub fn get_current_network_name(&self) -> Result<Option<String>, NetError>
Query the name of the network the host is currently connected to.
Returns Ok(None) when not started; Ok(Some(name)) when started and a
connected network name could be resolved; Ok(None) when started but no
name is available (or the platform is unsupported); returns
NetError::Lock if an internal lock is poisoned.
Sourcepub fn set_log_listener(
&self,
listener: Option<LogListener>,
) -> Result<(), NetError>
pub fn set_log_listener( &self, listener: Option<LogListener>, ) -> Result<(), NetError>
Install (or clear, with None) a listener for the engine’s internal
diagnostic log records.
Returns NetError::NotStarted when not started; returns
NetError::Lock if an internal lock is poisoned.