pub struct AsyncTcpSocket { /* private fields */ }Expand description
Asynchronous TCP socket built on top of Tokio.
Implementations§
Source§impl AsyncTcpSocket
impl AsyncTcpSocket
Sourcepub fn from_config(config: &TcpConfig) -> Result<Self>
pub fn from_config(config: &TcpConfig) -> Result<Self>
Create a socket from the given configuration without connecting.
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 (STREAM or RAW).
Sourcepub async fn connect(self, target: SocketAddr) -> Result<TcpStream>
pub async fn connect(self, target: SocketAddr) -> Result<TcpStream>
Connect to the target asynchronously.
Sourcepub async fn connect_timeout(
self,
target: SocketAddr,
timeout: Duration,
) -> Result<TcpStream>
pub async fn connect_timeout( self, target: SocketAddr, timeout: Duration, ) -> Result<TcpStream>
Connect with a timeout to the target address.
Sourcepub fn listen(self, backlog: i32) -> Result<TcpListener>
pub fn listen(self, backlog: i32) -> Result<TcpListener>
Start listening for incoming connections.
Sourcepub fn send_to(&self, buf: &[u8], target: SocketAddr) -> Result<usize>
pub fn send_to(&self, buf: &[u8], target: SocketAddr) -> Result<usize>
Send a raw TCP packet. Requires SockType::RAW.
Sourcepub fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)>
pub fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)>
Receive a raw TCP packet. Requires SockType::RAW.
Sourcepub fn set_reuseaddr(&self, on: bool) -> Result<()>
pub fn set_reuseaddr(&self, on: bool) -> Result<()>
Set reuse address option.
Sourcepub fn set_reuseport(&self, on: bool) -> Result<()>
pub fn set_reuseport(&self, on: bool) -> Result<()>
Set port reuse option where supported.
Sourcepub fn set_nodelay(&self, on: bool) -> Result<()>
pub fn set_nodelay(&self, on: bool) -> Result<()>
Set no delay option for TCP.
Sourcepub fn set_linger(&self, dur: Option<Duration>) -> Result<()>
pub fn set_linger(&self, dur: Option<Duration>) -> Result<()>
Set linger option for the socket.
Sourcepub fn set_hoplimit(&self, hops: u32) -> Result<()>
pub fn set_hoplimit(&self, hops: u32) -> Result<()>
Set the hop limit for IPv6 packets.
Sourcepub fn set_keepalive(&self, on: bool) -> Result<()>
pub fn set_keepalive(&self, on: bool) -> Result<()>
Set the keepalive option for the socket.
Sourcepub fn set_recv_buffer_size(&self, size: usize) -> Result<()>
pub fn set_recv_buffer_size(&self, size: usize) -> Result<()>
Set the receive buffer size.
Sourcepub fn recv_buffer_size(&self) -> Result<usize>
pub fn recv_buffer_size(&self) -> Result<usize>
Get the receive buffer size.
Sourcepub fn set_send_buffer_size(&self, size: usize) -> Result<()>
pub fn set_send_buffer_size(&self, size: usize) -> Result<()>
Set the send buffer size.
Sourcepub fn send_buffer_size(&self) -> Result<usize>
pub fn send_buffer_size(&self) -> Result<usize>
Get the send buffer size.
Sourcepub fn set_tclass_v6(&self, tclass: u32) -> Result<()>
pub fn set_tclass_v6(&self, tclass: u32) -> Result<()>
Set IPv6 traffic class where supported.
Sourcepub fn set_only_v6(&self, only_v6: bool) -> Result<()>
pub fn set_only_v6(&self, only_v6: bool) -> Result<()>
Set whether this socket is IPv6 only.
Sourcepub fn set_bind_device(&self, iface: &str) -> Result<()>
pub fn set_bind_device(&self, iface: &str) -> Result<()>
Set the bind device for the socket (Linux specific).
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Retrieve the local address of the socket.
Sourcepub fn into_tokio_stream(self) -> Result<TcpStream>
pub fn into_tokio_stream(self) -> Result<TcpStream>
Convert the internal socket into a Tokio TcpStream.
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.