pub struct OpenNet { /* private fields */ }Expand description
Top-level networking engine that owns runtime workers and named client instances.
Cloneable client handles remain valid until their named client is destroyed or the engine is dropped.
Implementations§
Source§impl OpenNet
impl OpenNet
Sourcepub fn new_with_network_config(config: NetworkConfig) -> Result<Self, NetError>
pub fn new_with_network_config(config: NetworkConfig) -> Result<Self, NetError>
Creates an engine with an immutable default network policy for WebSocket clients.
Proxy and TLS settings are validated before any work starts. This constructor currently applies only to WebSocket clients; use the per-client network-config constructor to override defaults.
Sourcepub fn new() -> Result<Self, NetError>
pub fn new() -> Result<Self, NetError>
Creates an engine with default settings and queue capacities of 128.
Sourcepub fn new_with_config(config: OpenNetConfig) -> Result<Self, NetError>
pub fn new_with_config(config: OpenNetConfig) -> Result<Self, NetError>
Creates an engine with the supplied runtime, queue capacities, and network policy.
Validates configuration before creating channels or workers. Invalid
capacities or worker counts return InvalidConfig; values remain fixed thereafter.
use open_net::{config::OpenNetConfig, NetError, OpenNet};
let net = OpenNet::new_with_config(
OpenNetConfig::default()
.with_async_queue_capacity(256)
.with_sync_queue_capacity(128),
)?;Sourcepub async fn create_ws_client(
&self,
thread_name: &str,
) -> Result<WebSocketClient, NetError>
pub async fn create_ws_client( &self, thread_name: &str, ) -> Result<WebSocketClient, NetError>
Creates a WebSocket client with default parameters and waits for its worker to become ready.
The returned client is disconnected; call connect or start_session to establish a session.
Sourcepub async fn create_ws_client_with_config(
&self,
thread_name: &str,
config: WebSocketClientConfig,
) -> Result<WebSocketClient, NetError>
pub async fn create_ws_client_with_config( &self, thread_name: &str, config: WebSocketClientConfig, ) -> Result<WebSocketClient, NetError>
Creates a WebSocket client with the supplied parameters and engine network policy.
Cancelling the wait does not cancel submitted creation; retrieve the
client later with get_ws_client and release it with destroy_ws_client.
Sourcepub async fn create_ws_client_with_network_config(
&self,
thread_name: &str,
config: WebSocketClientConfig,
network_config: NetworkConfig,
) -> Result<WebSocketClient, NetError>
pub async fn create_ws_client_with_network_config( &self, thread_name: &str, config: WebSocketClientConfig, network_config: NetworkConfig, ) -> Result<WebSocketClient, NetError>
Creates a WebSocket client with an immutable per-client proxy and TLS policy.
The supplied policy completely replaces engine defaults. default() selects
direct mode and WebPKI roots; connect, retry, and reconnect use this snapshot.
Waits for the worker to become ready but does not connect. Dropping the future does not cancel creation; retrieve and later destroy the client by name.
use open_net::{network::{NetworkConfig, ProxyConfig}, ws::WebSocketClientConfig, NetError, OpenNet};
let defaults = NetworkConfig::default()
.with_proxy(ProxyConfig::http_connect("http://127.0.0.1:8080", None)?);
let net = OpenNet::new_with_network_config(defaults.clone())?;
let inherited = net.create_ws_client("inherited").await?;
let direct = net.create_ws_client_with_network_config(
"direct", WebSocketClientConfig::default(), NetworkConfig::default(),
).await?;
let other = net.create_ws_client_with_network_config(
"other", WebSocketClientConfig::default(),
defaults.with_proxy(ProxyConfig::http_connect("http://127.0.0.1:8081", None)?),
).await?;
net.destroy_ws_client("inherited").await?;
net.destroy_ws_client("direct").await?;
net.destroy_ws_client("other").await?;Sourcepub fn get_ws_client(
&self,
thread_name: &str,
) -> Result<WebSocketClient, NetError>
pub fn get_ws_client( &self, thread_name: &str, ) -> Result<WebSocketClient, NetError>
Returns a shared handle to an existing WebSocket client.
Source§impl OpenNet
impl OpenNet
Sourcepub fn network_status_context(&self) -> NetworkStatusContext
pub fn network_status_context(&self) -> NetworkStatusContext
Export this engine’s cached network state for an explicitly configured standalone HTTP client. Reading the context never starts monitoring. The context remains bound to this engine and becomes Closed on engine drop.
Sourcepub async fn create_net_status_client(
&self,
thread_name: &str,
) -> Result<NetStatusClient, NetError>
pub async fn create_net_status_client( &self, thread_name: &str, ) -> Result<NetStatusClient, NetError>
Creates a network-status client; call start().await to begin monitoring.
Names are trimmed and must be unique within an engine. Requires the
net-status feature, also enabled by http-client and ws-client.
use open_net::{NetError, OpenNet};
let net = OpenNet::new()?;
let client = net.create_net_status_client("network-status").await?;
client.start().await?;
let snapshot = client.snapshot()?;
let status = snapshot.reachability;
let ip_stack = snapshot.ip_stack;
net.destroy_net_status_client("network-status").await?;Sourcepub fn get_net_status_client(
&self,
thread_name: &str,
) -> Result<NetStatusClient, NetError>
pub fn get_net_status_client( &self, thread_name: &str, ) -> Result<NetStatusClient, NetError>
Returns a shared handle to a named network-status client.
Sourcepub async fn destroy_net_status_client(
&self,
thread_name: &str,
) -> Result<(), NetError>
pub async fn destroy_net_status_client( &self, thread_name: &str, ) -> Result<(), NetError>
Permanently stops a client, waits for monitoring to exit, and releases its name.
Cancelling the wait does not cancel submitted destruction; the name remains
reserved until cleanup completes. Use NetStatusClient::stop to pause instead.