pub struct RawSocket<'d> { /* private fields */ }Expand description
An Raw socket.
Implementations§
Source§impl<'d> RawSocket<'d>
impl<'d> RawSocket<'d>
Sourcepub fn new(
stack: Stack<'d>,
ip_version: Option<IpVersion>,
ip_protocol: Option<IpProtocol>,
) -> Result<Self, Full>
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:
Fullif the stack has no room for another raw socket. The limit is set by theraw-socket-count-Nfeature ofxarxa.
Sourcepub fn new_unbound(stack: Stack<'d>) -> Result<Self, Full>
pub fn new_unbound(stack: Stack<'d>) -> Result<Self, Full>
Create a new raw socket using the provided stack, without binding it.
Errors:
Fullif the stack has no room for another raw socket. The limit is set by theraw-socket-count-Nfeature ofxarxa.
Sourcepub fn bind(&mut self, mode: RawMode) -> Result<(), BindError>
pub fn bind(&mut self, mode: RawMode) -> Result<(), BindError>
Bind the socket to the given mode.
Sourcepub fn bind_to_iface(
&mut self,
iface: Option<IfaceHandle>,
) -> Result<(), BindError>
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.
Sourcepub fn bound_iface(&self) -> Option<IfaceHandle>
pub fn bound_iface(&self) -> Option<IfaceHandle>
Return the interface the socket is bound to, or None.
See bind_to_iface.
Sourcepub fn wait_recv_ready(&self) -> impl Future<Output = ()> + '_
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.
Sourcepub fn poll_recv_ready(&self, cx: &mut Context<'_>) -> Poll<()>
pub fn poll_recv_ready(&self, cx: &mut Context<'_>) -> Poll<()>
Wait until a packet can be read.
Sourcepub fn recv<'s>(
&'s self,
buf: &'s mut [u8],
) -> impl Future<Output = Result<usize, RecvError>> + 's
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.
Sourcepub fn try_recv(&self, buf: &mut [u8]) -> Result<usize, TryError<RecvError>>
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).
Sourcepub fn poll_recv(
&self,
buf: &mut [u8],
cx: &mut Context<'_>,
) -> Poll<Result<usize, RecvError>>
pub fn poll_recv( &self, buf: &mut [u8], cx: &mut Context<'_>, ) -> Poll<Result<usize, RecvError>>
Receive a packet, copying it into the given buffer.
Sourcepub async fn recv_packet(&self) -> Result<PacketBuf, RecvError>
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).
Sourcepub async fn recv_with<F, R>(&mut self, f: F) -> Result<R, RecvError>
pub async fn recv_with<F, R>(&mut self, f: F) -> Result<R, RecvError>
Receive a packet with a zero-copy function.
This method will wait until a packet is received.
Sourcepub fn wait_send_ready(&self) -> impl Future<Output = ()> + '_
pub fn wait_send_ready(&self) -> impl Future<Output = ()> + '_
Wait until the socket becomes writable.
Sourcepub fn poll_send_ready(&self, cx: &mut Context<'_>) -> Poll<()>
pub fn poll_send_ready(&self, cx: &mut Context<'_>) -> Poll<()>
Wait until a packet can be sent.
Sourcepub async fn send(&self, buf: &[u8]) -> Result<(), SendError>
pub async fn send(&self, buf: &[u8]) -> Result<(), SendError>
Send a packet.
This method will wait until the packet has been sent.
Sourcepub async fn send_with_meta(
&self,
buf: &[u8],
meta: PacketMeta,
) -> Result<(), SendError>
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.
Sourcepub fn try_send(&self, buf: &[u8]) -> Result<(), TryError<SendError>>
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.
Sourcepub fn poll_send_with_meta(
&self,
buf: &[u8],
meta: PacketMeta,
cx: &mut Context<'_>,
) -> Poll<Result<(), SendError>>
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.