Skip to main content

Netstack

Struct Netstack 

Source
pub struct Netstack<D> { /* private fields */ }
Expand description

A userspace network stack.

This is a relatively thin shell around CoreStack to provide convenience runtime features.

Implementations§

Source§

impl<D> Netstack<D>

Source

pub fn with_clock(dev: D, config: Config, clock: Clock) -> Self

Construct a new netstack with the given device, configuration, and clock.

Source

pub fn run_blocking(&mut self, poll_delay: Duration)
where D: Device,

Run the netstack, driving the internal event loop to consume commands.

Runs forever, blocking the current thread.

poll_delay is the amount of time to sleep when we’re done with I/O and commands to process: a smaller delay improves latency at the cost of CPU cycles spent polling. Consider the async methods for an event-driven approach.

Source

pub async fn run_with_sleep(&mut self, sleep: impl AsyncFn(Duration) + Clone)

Run the netstack, driving the internal event loop to consume commands.

The sleep function is the runtime-specific sleep implementation. It has the Clone bound for esoteric async type system reasons (the loop needs to call the function multiple times, but it doesn’t want to reason about &impl AsyncFn). A normal closure or async fn ref will satisfy the bound.

Trait Implementations§

Source§

impl<D> HasChannel for Netstack<D>

Source§

fn borrow_channel(&self) -> impl Borrow<Channel> + Send

Retrieve a Channel borrow. Read more
Source§

fn command_channel(&self) -> WeakSender<Request>

Clone a new command channel.
Source§

fn request_blocking( &self, handle: Option<SocketHandle>, command: impl Into<Command>, ) -> Result<Response, ChannelClosedError>

Send a request through the channel. Read more
Source§

fn request( &self, handle: Option<SocketHandle>, command: impl Into<Command>, ) -> impl Future<Output = Result<Response, Error>> + Send

Asynchronously send a request through the channel. Read more
Source§

fn request_nonblocking( &self, handle: Option<SocketHandle>, command: impl Into<Command>, ) -> Result<(), ChannelClosedError>

Send a nonblocking request, discarding any response. Read more

Auto Trait Implementations§

§

impl<D> !RefUnwindSafe for Netstack<D>

§

impl<D> !UnwindSafe for Netstack<D>

§

impl<D> Freeze for Netstack<D>
where D: Freeze,

§

impl<D> Send for Netstack<D>
where D: Send,

§

impl<D> Sync for Netstack<D>
where D: Sync,

§

impl<D> Unpin for Netstack<D>
where D: Unpin,

§

impl<D> UnsafeUnpin for Netstack<D>
where D: UnsafeUnpin,

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> CreateSocket for T
where T: HasChannel + Sync,

Source§

fn udp_bind_blocking(&self, endpoint: SocketAddr) -> Result<UdpSocket, Error>

Create and bind a new UdpSocket to the given local endpoint.
Source§

async fn udp_bind(&self, endpoint: SocketAddr) -> Result<UdpSocket, Error>

Asynchronously create and bind a new UdpSocket to the given local endpoint.
Source§

fn tcp_listen_blocking( &self, local_endpoint: SocketAddr, ) -> Result<TcpListener, Error>

Create a new TcpListener on the given endpoint.
Source§

async fn tcp_listen( &self, local_endpoint: SocketAddr, ) -> Result<TcpListener, Error>

Asynchronously create a new TcpListener on the given endpoint.
Source§

fn bound_tcp_ports_blocking(&self) -> Result<Vec<u16>, Error>

Snapshot the set of local ports that currently have an explicit TCP listener. Read more
Source§

async fn bound_tcp_ports(&self) -> Result<Vec<u16>, Error>

Asynchronously snapshot the set of local ports that currently have an explicit TCP listener. See CreateSocket::bound_tcp_ports_blocking.
Source§

fn tcp_connect_blocking( &self, local_endpoint: SocketAddr, remote_endpoint: SocketAddr, ) -> Result<TcpStream, Error>

Create a new TcpStream bound to the given local address and connected to the given remote. Read more
Source§

async fn tcp_connect( &self, local_endpoint: SocketAddr, remote_endpoint: SocketAddr, ) -> Result<TcpStream, Error>

Asynchronously create a new TcpStream bound to the given local address and connected to the given remote. Read more
Source§

fn raw_open_blocking( &self, ipv4: bool, ip_protocol: Protocol, ) -> Result<RawSocket, Error>

Create a new RawSocket on the selected ip version and protocol. Read more
Source§

async fn raw_open( &self, ipv4: bool, ip_protocol: Protocol, ) -> Result<RawSocket, Error>

Asynchronously create a new RawSocket on the selected ip version and protocol. 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> NetstackControl for T
where T: HasChannel,

Source§

fn set_ips_blocking( &self, ips: impl IntoIterator<Item = IpAddr>, ) -> Result<(), Error>

Set the IPs for the netstack interface. Read more
Source§

fn set_ips( &self, ips: impl IntoIterator<Item = IpAddr>, ) -> impl Future<Output = Result<(), Error>> + Send

Set the IPs for the netstack interface. Read more
Source§

fn set_any_ip_blocking(&self, enabled: bool) -> Result<(), Error>

Enable or disable “any-IP” acceptance on the netstack interface. Read more
Source§

fn set_any_ip( &self, enabled: bool, ) -> impl Future<Output = Result<(), Error>> + Send

Enable or disable “any-IP” acceptance on the netstack interface. Read more
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