Struct socks5_server::connection::associate::AssociatedUdpSocket
source · pub struct AssociatedUdpSocket { /* private fields */ }Expand description
A wrapper of a tokio UDP socket dealing with SOCKS5 UDP header.
(UdpSocket, usize) and AssociatedUdpSocket can be converted to each other with From trait, in which usize is the maximum receiving UDP packet size, with SOCKS5 UDP header included.
It only provides handful of methods to send / receive UDP packets with SOCKS5 UDP header. However, the underlying UdpSocket can be accessed with AsRef and AsMut trait, so you can use all methods provided by UdpSocket.
Implementations§
source§impl AssociatedUdpSocket
impl AssociatedUdpSocket
sourcepub fn get_max_pkt_size(&self) -> usize
pub fn get_max_pkt_size(&self) -> usize
Get the maximum receiving UDP packet size, with SOCKS5 UDP header included.
sourcepub fn set_max_pkt_size(&self, size: usize)
pub fn set_max_pkt_size(&self, size: usize)
Set the maximum receiving UDP packet size, with SOCKS5 UDP header included, for adjusting the receiving buffer size.
sourcepub async fn recv(
&self
) -> Result<(Bytes, UdpHeader), (Socks5Error, Option<Vec<u8>>)>
pub async fn recv( &self ) -> Result<(Bytes, UdpHeader), (Socks5Error, Option<Vec<u8>>)>
Receives a SOCKS5 UDP packet on the socket from the remote address which it is connected.
On success, it returns the packet payload and the SOCKS5 UDP header. On error, it returns the error alongside an Option<Vec<u8>>. If the error occurs before / when receiving the raw UDP packet, the Option<Vec<u8>> will be None. Otherwise, it will be Some(Vec<u8>) containing the received raw UDP packet.
sourcepub async fn recv_from(
&self
) -> Result<(Bytes, UdpHeader, SocketAddr), (Socks5Error, Option<Vec<u8>>)>
pub async fn recv_from( &self ) -> Result<(Bytes, UdpHeader, SocketAddr), (Socks5Error, Option<Vec<u8>>)>
Receives a SOCKS5 UDP packet on the socket from a remote address.
On success, it returns the packet payload, the SOCKS5 UDP header and the source address. On error, it returns the error alongside an Option<Vec<u8>>. If the error occurs before / when receiving the raw UDP packet, the Option<Vec<u8>> will be None. Otherwise, it will be Some(Vec<u8>) containing the received raw UDP packet.