Struct embassy_net::Stack
source · pub struct Stack<'d> { /* private fields */ }
Expand description
Network stack handle
Use this to create sockets. It’s Copy
, so you can pass
it by value instead of by reference.
Implementations§
source§impl<'d> Stack<'d>
impl<'d> Stack<'d>
sourcepub fn hardware_address(&self) -> HardwareAddress
pub fn hardware_address(&self) -> HardwareAddress
Get the hardware address of the network interface.
sourcepub fn is_link_up(&self) -> bool
pub fn is_link_up(&self) -> bool
Get whether the link is up.
sourcepub fn is_config_up(&self) -> bool
pub fn is_config_up(&self) -> bool
Get whether the network stack has a valid IP configuration. This is true if the network stack has a static IP configuration or if DHCP has completed
sourcepub async fn wait_link_up(&self)
pub async fn wait_link_up(&self)
Wait for the network device to obtain a link signal.
sourcepub async fn wait_link_down(&self)
pub async fn wait_link_down(&self)
Wait for the network device to lose link signal.
sourcepub async fn wait_config_up(&self)
pub async fn wait_config_up(&self)
Wait for the network stack to obtain a valid IP configuration.
§Notes:
-
Ensure
Runner::run
has been started before using this function. -
This function may never return (e.g. if no configuration is obtained through DHCP). The caller is supposed to handle a timeout for this case.
§Example
let config = embassy_net::Config::dhcpv4(Default::default());
// Init network stack
// NOTE: DHCP and DNS need one socket slot if enabled. This is why we're
// provisioning space for 3 sockets here: one for DHCP, one for DNS, and one for your code (e.g. TCP).
// If you use more sockets you must increase this. If you don't enable DHCP or DNS you can decrease it.
static RESOURCES: StaticCell<embassy_net::StackResources<3>> = StaticCell::new();
let (stack, runner) = embassy_net::new(
driver,
config,
RESOURCES.init(embassy_net::StackResources::new()),
seed
);
// Launch network task that runs `runner.run().await`
spawner.spawn(net_task(runner)).unwrap();
// Wait for DHCP config
stack.wait_config_up().await;
// use the network stack
// ...
sourcepub async fn wait_config_down(&self)
pub async fn wait_config_down(&self)
Wait for the network stack to lose a valid IP configuration.
sourcepub fn config_v4(&self) -> Option<StaticConfigV4>
pub fn config_v4(&self) -> Option<StaticConfigV4>
Get the current IPv4 configuration.
If using DHCP, this will be None if DHCP hasn’t been able to acquire an IP address, or Some if it has.
sourcepub fn config_v6(&self) -> Option<StaticConfigV6>
pub fn config_v6(&self) -> Option<StaticConfigV6>
Get the current IPv6 configuration.
sourcepub fn set_config_v4(&self, config: ConfigV4)
pub fn set_config_v4(&self, config: ConfigV4)
Set the IPv4 configuration.
sourcepub fn set_config_v6(&self, config: ConfigV6)
pub fn set_config_v6(&self, config: ConfigV6)
Set the IPv6 configuration.
source§impl<'d> Stack<'d>
impl<'d> Stack<'d>
sourcepub fn join_multicast_group(
&self,
addr: impl Into<IpAddress>,
) -> Result<(), MulticastError>
pub fn join_multicast_group( &self, addr: impl Into<IpAddress>, ) -> Result<(), MulticastError>
Join a multicast group.
sourcepub fn leave_multicast_group(
&self,
addr: impl Into<IpAddress>,
) -> Result<(), MulticastError>
pub fn leave_multicast_group( &self, addr: impl Into<IpAddress>, ) -> Result<(), MulticastError>
Leave a multicast group.
sourcepub fn has_multicast_group(&self, addr: impl Into<IpAddress>) -> bool
pub fn has_multicast_group(&self, addr: impl Into<IpAddress>) -> bool
Get whether the network stack has joined the given multicast group.
Trait Implementations§
Auto Trait Implementations§
impl<'d> Freeze for Stack<'d>
impl<'d> !RefUnwindSafe for Stack<'d>
impl<'d> !Send for Stack<'d>
impl<'d> !Sync for Stack<'d>
impl<'d> Unpin for Stack<'d>
impl<'d> !UnwindSafe for Stack<'d>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)