embassy-net

Crates

git

Versions

default

Flavors

Skip to main content

RawSocket

Struct RawSocket 

Source
pub struct RawSocket<'d> { /* private fields */ }
Expand description

An Raw socket.

Implementations§

Source§

impl<'d> RawSocket<'d>

Source

pub fn new( stack: Stack<'d>, ip_version: Option<IpVersion>, ip_protocol: Option<IpProtocol>, ) -> Result<Self, Full>

Create a new raw socket using the provided stack, receiving IP packets of the given version and protocol (None for any).

Errors:

  • Full if the stack has no room for another raw socket. The limit is set by the raw-socket-count-N feature of xarxa.
Source

pub fn new_unbound(stack: Stack<'d>) -> Result<Self, Full>

Create a new raw socket using the provided stack, without binding it.

Errors:

  • Full if the stack has no room for another raw socket. The limit is set by the raw-socket-count-N feature of xarxa.
Source

pub fn bind(&mut self, mode: RawMode) -> Result<(), BindError>

Bind the socket to the given mode.

Source

pub fn bind_to_iface( &mut self, iface: Option<IfaceHandle>, ) -> Result<(), BindError>

Bind the socket to an interface, or unbind it with None.

A socket bound to an interface only sends and receives packets on it.

The socket must be closed. The binding is kept across close, so a socket stays bound to its interface when it is bound again.

Returns Err(BindError::InvalidState) if the socket is open.

Source

pub fn bound_iface(&self) -> Option<IfaceHandle>

Return the interface the socket is bound to, or None.

See bind_to_iface.

Source

pub fn wait_recv_ready(&self) -> impl Future<Output = ()> + '_

Wait until the socket becomes readable.

A socket is readable when a packet has been received, or when there are queued packets in the buffer.

Source

pub fn poll_recv_ready(&self, cx: &mut Context<'_>) -> Poll<()>

Wait until a packet can be read.

Source

pub fn recv<'s>( &'s self, buf: &'s mut [u8], ) -> impl Future<Output = Result<usize, RecvError>> + 's

Receive a packet, copying it into the given buffer.

This method will wait until a packet is received.

If the socket is not bound, this method will return Err(RecvError::InvalidState).

Returns the number of bytes received.

Source

pub fn try_recv(&self, buf: &mut [u8]) -> Result<usize, TryError<RecvError>>

Receive a packet, copying it into the given buffer.

This method will not wait for a packet to be received.

If no packet is available, this method will return Err(TryError::WouldBlock).

Source

pub fn poll_recv( &self, buf: &mut [u8], cx: &mut Context<'_>, ) -> Poll<Result<usize, RecvError>>

Receive a packet, copying it into the given buffer.

Source

pub async fn recv_packet(&self) -> Result<PacketBuf, RecvError>

Receive a packet, taking ownership of its buffer.

This method will wait until a packet is received.

If the socket is not bound, this method will return Err(RecvError::InvalidState).

Source

pub async fn recv_with<F, R>(&mut self, f: F) -> Result<R, RecvError>
where F: FnOnce(&[u8], PacketMeta) -> R,

Receive a packet with a zero-copy function.

This method will wait until a packet is received.

Source

pub fn wait_send_ready(&self) -> impl Future<Output = ()> + '_

Wait until the socket becomes writable.

Source

pub fn poll_send_ready(&self, cx: &mut Context<'_>) -> Poll<()>

Wait until a packet can be sent.

Source

pub async fn send(&self, buf: &[u8]) -> Result<(), SendError>

Send a packet.

This method will wait until the packet has been sent.

Source

pub async fn send_with_meta( &self, buf: &[u8], meta: PacketMeta, ) -> Result<(), SendError>

Send a packet with the given metadata attached.

This method will wait until the packet has been sent.

Source

pub fn try_send(&self, buf: &[u8]) -> Result<(), TryError<SendError>>

Send a packet.

This method will not wait for a packet buffer or device room to become free.

Source

pub fn poll_send_with_meta( &self, buf: &[u8], meta: PacketMeta, cx: &mut Context<'_>, ) -> Poll<Result<(), SendError>>

Send a packet with the given metadata attached.

Source

pub async fn send_with<F, R>( &mut self, max_size: usize, f: F, ) -> Result<R, SendError>
where F: FnOnce(&mut [u8]) -> (usize, R),

Send a packet with a zero-copy function.

This method will wait until a packet buffer is available before passing it to the closure. The closure returns the number of bytes written into the buffer.

Source

pub fn is_open(&self) -> bool

Returns whether the socket is bound.

Source

pub fn close(&mut self)

Close the socket.

Trait Implementations§

Source§

impl Drop for RawSocket<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'d> !RefUnwindSafe for RawSocket<'d>

§

impl<'d> !Send for RawSocket<'d>

§

impl<'d> !Sync for RawSocket<'d>

§

impl<'d> !UnwindSafe for RawSocket<'d>

§

impl<'d> Freeze for RawSocket<'d>

§

impl<'d> Unpin for RawSocket<'d>

§

impl<'d> UnsafeUnpin for RawSocket<'d>

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.