pub struct Socket<A, S> { /* private fields */ }Expand description
A UDP network socket.
Implementations§
Source§impl<A: NetworkAddress, S> Socket<A, S>
impl<A: NetworkAddress, S> Socket<A, S>
Sourcepub fn local_addr(&self) -> A
pub fn local_addr(&self) -> A
The local address at which the socket is listening.
Sourcepub fn poll_recv(
&self,
buf: &mut [u8],
cx: &mut Context<'_>,
) -> Poll<Result<RecvResult<A>>>
pub fn poll_recv( &self, buf: &mut [u8], cx: &mut Context<'_>, ) -> Poll<Result<RecvResult<A>>>
Sourcepub async fn recv(&self, buf: &mut [u8]) -> Result<RecvResult<A>>
pub async fn recv(&self, buf: &mut [u8]) -> Result<RecvResult<A>>
Receive a datagram.
§Errors
May return errors for previous send operations, or if it is no longer possible to receive on the given socket.
Sourcepub fn get_send_timestamp(
&self,
) -> impl Future<Output = Result<(SendTimestampToken, TimestampData)>> + Send + Sync + 'static
pub fn get_send_timestamp( &self, ) -> impl Future<Output = Result<(SendTimestampToken, TimestampData)>> + Send + Sync + 'static
Wait for the next send timestamp to be returned.
Note: There is no poll variant for this function, as that is currently impossible to implement with the tools tokio provides. To compensate, the future returned here is independent of the self reference and can be stored to simulate the existence of a poll function.
§Errors
May fail if the timestamp is not available, or if the network had issues sending the message.
Source§impl<A: NetworkAddress> Socket<A, Open>
impl<A: NetworkAddress> Socket<A, Open>
Sourcepub fn poll_send_to(
&self,
buf: &[u8],
addr: A,
cx: &mut Context<'_>,
) -> Poll<Result<Option<SendTimestampToken>>>
pub fn poll_send_to( &self, buf: &[u8], addr: A, cx: &mut Context<'_>, ) -> Poll<Result<Option<SendTimestampToken>>>
Sourcepub async fn send_to(&mut self, buf: &[u8], addr: A) -> Result<TimestampData>
pub async fn send_to(&mut self, buf: &[u8], addr: A) -> Result<TimestampData>
Send a packet to a given receiver on the socket.
When used in combination with the polling send functions, if there are timestamps
pending for some SendTimestampToken, these may be skipped and become unavailable
when calling this function.
§Errors
May fail if the remote cannot be reached.
Sourcepub fn poll_send_from_to(
&self,
buf: &[u8],
from: A,
to: A,
cx: &mut Context<'_>,
) -> Poll<Result<Option<SendTimestampToken>>>
pub fn poll_send_from_to( &self, buf: &[u8], from: A, to: A, cx: &mut Context<'_>, ) -> Poll<Result<Option<SendTimestampToken>>>
Sourcepub async fn send_from_to(
&mut self,
buf: &[u8],
from: A,
to: A,
) -> Result<TimestampData>
pub async fn send_from_to( &mut self, buf: &[u8], from: A, to: A, ) -> Result<TimestampData>
Send a packet to a given receiver on the socket, using the specified origin address.
When used in combination with the polling send functions, if there are timestamps
pending for some SendTimestampToken, these may be skipped and become unavailable
when calling this function.
§Errors
May fail if the from or to address is not available or reachable.
Source§impl<A: NetworkAddress> Socket<A, Connected>
impl<A: NetworkAddress> Socket<A, Connected>
Sourcepub fn peer_addr(&self) -> Result<A>
pub fn peer_addr(&self) -> Result<A>
Address of the remote to which this socket is connected.
§Errors
May error if the operating system cannot provide the addres of the peer.
Sourcepub fn poll_send(
&self,
buf: &[u8],
cx: &mut Context<'_>,
) -> Poll<Result<Option<SendTimestampToken>>>
pub fn poll_send( &self, buf: &[u8], cx: &mut Context<'_>, ) -> Poll<Result<Option<SendTimestampToken>>>
Sourcepub async fn send(&mut self, buf: &[u8]) -> Result<TimestampData>
pub async fn send(&mut self, buf: &[u8]) -> Result<TimestampData>
Send a packet on the socket.
When used in combination with the polling send functions, if there are timestamps
pending for some SendTimestampToken, these may be skipped and become unavailable
when calling this function.
§Errors
May fail if the remote or network this socket is attached to is no longer available, or if the timestamp for the operation cannot be obtained.
Sourcepub fn poll_send_from(
&self,
buf: &[u8],
from: A,
cx: &mut Context<'_>,
) -> Poll<Result<Option<SendTimestampToken>>>
pub fn poll_send_from( &self, buf: &[u8], from: A, cx: &mut Context<'_>, ) -> Poll<Result<Option<SendTimestampToken>>>
Sourcepub async fn send_from(&mut self, buf: &[u8], from: A) -> Result<TimestampData>
pub async fn send_from(&mut self, buf: &[u8], from: A) -> Result<TimestampData>
Send a packet on the socket, with the given local address.
When used in combination with the polling send functions, if there are timestamps
pending for some SendTimestampToken, these may be skipped and become unavailable
when calling this function.
§Errors
May error if the remote cannot be reached, or if the network the socket is attached to is no longer available.
Source§impl<A: MulticastJoinable, S> Socket<A, S>
impl<A: MulticastJoinable, S> Socket<A, S>
Sourcepub fn join_multicast(&self, addr: A, interface: InterfaceName) -> Result<()>
pub fn join_multicast(&self, addr: A, interface: InterfaceName) -> Result<()>
Indicate that you want to receive messages for a specific multicast address on the socket.
§Errors
May error if it is not possible to unsubscribe from the given address.
Sourcepub fn leave_multicast(&self, addr: A, interface: InterfaceName) -> Result<()>
pub fn leave_multicast(&self, addr: A, interface: InterfaceName) -> Result<()>
Indicate that you no longer want to receive messages for a specific multicast address on the socket.
§Errors
May error if it is not possible to unsubscribe from the given address.