pub struct UdpSocket { /* private fields */ }Expand description
Synchronous low level UDP socket.
Implementations§
Source§impl UdpSocket
impl UdpSocket
Sourcepub fn from_config(config: &UdpConfig) -> Result<Self>
pub fn from_config(config: &UdpConfig) -> Result<Self>
Create a socket from the provided configuration.
Sourcepub fn new(domain: Domain, sock_type: SockType) -> Result<Self>
pub fn new(domain: Domain, sock_type: SockType) -> Result<Self>
Create a socket of arbitrary type (DGRAM or RAW).
Sourcepub fn send_msg(
&self,
buf: &[u8],
target: SocketAddr,
meta: Option<&UdpSendMeta>,
) -> Result<usize>
pub fn send_msg( &self, buf: &[u8], target: SocketAddr, meta: Option<&UdpSendMeta>, ) -> Result<usize>
Send data with ancillary metadata (sendmsg on Unix).
When supported by the current OS, source address and interface index are propagated using packet-info control messages.
Sourcepub fn recv_msg(&self, buf: &mut [u8]) -> Result<UdpRecvMeta>
pub fn recv_msg(&self, buf: &mut [u8]) -> Result<UdpRecvMeta>
Receive data with ancillary metadata (recvmsg on Unix).
This allows extracting packet-info control messages such as destination
address and incoming interface index when enabled with
set_recv_pktinfo_v4 / set_recv_pktinfo_v6.
pub fn set_ttl(&self, ttl: u32) -> Result<()>
pub fn ttl(&self) -> Result<u32>
pub fn set_hoplimit(&self, hops: u32) -> Result<()>
pub fn hoplimit(&self) -> Result<u32>
pub fn set_reuseaddr(&self, on: bool) -> Result<()>
pub fn reuseaddr(&self) -> Result<bool>
pub fn set_reuseport(&self, on: bool) -> Result<()>
pub fn reuseport(&self) -> Result<bool>
pub fn set_broadcast(&self, on: bool) -> Result<()>
pub fn broadcast(&self) -> Result<bool>
pub fn set_recv_buffer_size(&self, size: usize) -> Result<()>
pub fn recv_buffer_size(&self) -> Result<usize>
pub fn set_send_buffer_size(&self, size: usize) -> Result<()>
pub fn send_buffer_size(&self) -> Result<usize>
pub fn set_tos(&self, tos: u32) -> Result<()>
pub fn tos(&self) -> Result<u32>
pub fn set_tclass_v6(&self, tclass: u32) -> Result<()>
pub fn tclass_v6(&self) -> Result<u32>
pub fn set_only_v6(&self, only_v6: bool) -> Result<()>
pub fn only_v6(&self) -> Result<bool>
pub fn set_keepalive(&self, on: bool) -> Result<()>
pub fn keepalive(&self) -> Result<bool>
Sourcepub fn set_recv_pktinfo_v4(&self, on: bool) -> Result<()>
pub fn set_recv_pktinfo_v4(&self, on: bool) -> Result<()>
Enable IPv4 packet-info ancillary data receiving (IP_PKTINFO) where supported.
Sourcepub fn set_recv_pktinfo_v6(&self, on: bool) -> Result<()>
pub fn set_recv_pktinfo_v6(&self, on: bool) -> Result<()>
Enable IPv6 packet-info ancillary data receiving (IPV6_RECVPKTINFO) where supported.
Sourcepub fn recv_pktinfo_v4(&self) -> Result<bool>
pub fn recv_pktinfo_v4(&self) -> Result<bool>
Query whether IPv4 packet-info ancillary data receiving is enabled.
Sourcepub fn recv_pktinfo_v6(&self) -> Result<bool>
pub fn recv_pktinfo_v6(&self) -> Result<bool>
Query whether IPv6 packet-info ancillary data receiving is enabled.
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Retrieve the local socket address.
Sourcepub fn to_std(self) -> Result<StdUdpSocket>
pub fn to_std(self) -> Result<StdUdpSocket>
Convert into a raw std::net::UdpSocket.
Sourcepub fn from_socket(socket: Socket) -> Self
pub fn from_socket(socket: Socket) -> Self
Construct from a raw socket2::Socket.
Sourcepub fn into_socket(self) -> Socket ⓘ
pub fn into_socket(self) -> Socket ⓘ
Consume and return the inner socket2::Socket.