pub struct Datagram { /* private fields */ }
l2cap
only.Expand description
An L2CAP datagram socket (connection-less, unreliable messages of a fixed maximum length).
Implementations
sourceimpl Datagram
impl Datagram
sourcepub async fn bind(sa: SocketAddr) -> Result<Self>
pub async fn bind(sa: SocketAddr) -> Result<Self>
Creates a new datagram socket, which will be bound to the specified socket address.
Specify SocketAddr::any_br_edr or SocketAddr::any_le for any local adapter address with a dynamically allocated PSM.
sourcepub async fn connect(&self, sa: SocketAddr) -> Result<()>
pub async fn connect(&self, sa: SocketAddr) -> Result<()>
Establish a datagram connection with a peer at the specified socket address.
sourcepub fn peer_addr(&self) -> Result<SocketAddr>
pub fn peer_addr(&self) -> Result<SocketAddr>
Gets the peer address of this stream.
sourcepub async fn send(&self, buf: &[u8]) -> Result<usize>
pub async fn send(&self, buf: &[u8]) -> Result<usize>
Sends a packet to the connected peer.
The packet length must not exceed the Self::send_mtu.
sourcepub fn poll_send(&self, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>>
pub fn poll_send(&self, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>>
Attempts to send a packet to the connected peer.
The packet length must not exceed the Self::send_mtu.
sourcepub async fn send_to(&self, buf: &[u8], target: SocketAddr) -> Result<usize>
pub async fn send_to(&self, buf: &[u8], target: SocketAddr) -> Result<usize>
Sends a packet to the specified target address.
The packet length must not exceed the Self::send_mtu.
sourcepub fn poll_send_to(
&self,
cx: &mut Context<'_>,
buf: &[u8],
target: SocketAddr
) -> Poll<Result<usize>>
pub fn poll_send_to(
&self,
cx: &mut Context<'_>,
buf: &[u8],
target: SocketAddr
) -> Poll<Result<usize>>
Attempts to send a packet to the specified target address.
The packet length must not exceed the Self::send_mtu.
sourcepub async fn recv(&self, buf: &mut [u8]) -> Result<usize>
pub async fn recv(&self, buf: &mut [u8]) -> Result<usize>
Receives a packet from the connected peer.
The provided buffer must be of length Self::recv_mtu, otherwise the packet may be truncated.
sourcepub fn poll_recv(
&self,
cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>
) -> Poll<Result<()>>
pub fn poll_recv(
&self,
cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>
) -> Poll<Result<()>>
Attempts to receive a packet from the connected peer.
The provided buffer must be of length Self::recv_mtu, otherwise the packet may be truncated.
sourcepub async fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)>
pub async fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)>
Receives a packet from anywhere.
The provided buffer must be of length Self::recv_mtu, otherwise the packet may be truncated.
sourcepub fn poll_recv_from(
&self,
cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>
) -> Poll<Result<SocketAddr>>
pub fn poll_recv_from(
&self,
cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>
) -> Poll<Result<SocketAddr>>
Attempts to receive a packet from anywhere.
The provided buffer must be of length Self::recv_mtu, otherwise the packet may be truncated.
sourcepub fn shutdown(&self, how: Shutdown) -> Result<()>
pub fn shutdown(&self, how: Shutdown) -> Result<()>
Shuts down the read, write, or both halves of this connection.
sourcepub unsafe fn from_raw_fd(fd: RawFd) -> Result<Self>
pub unsafe fn from_raw_fd(fd: RawFd) -> Result<Self>
Constructs a new Datagram from the given raw file descriptor.
The file descriptor must have been set to non-blocking mode.
This function consumes ownership of the specified file descriptor. The returned object will take responsibility for closing it when the object goes out of scope.
Safety
If the passed file descriptor is invalid, undefined behavior may occur.
Trait Implementations
sourceimpl FromRawFd for Datagram
impl FromRawFd for Datagram
sourceunsafe fn from_raw_fd(fd: RawFd) -> Self
unsafe fn from_raw_fd(fd: RawFd) -> Self
Constructs a new instance of Self
from the given raw file
descriptor.
The file descriptor must have been set to non-blocking mode.
Panics
Panics when the conversion fails. Use Datagram::from_raw_fd for a non-panicking variant.
Auto Trait Implementations
impl !RefUnwindSafe for Datagram
impl Send for Datagram
impl Sync for Datagram
impl Unpin for Datagram
impl !UnwindSafe for Datagram
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more