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_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_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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AsyncTcpSocket
impl RefUnwindSafe for AsyncTcpSocket
impl Send for AsyncTcpSocket
impl Sync for AsyncTcpSocket
impl Unpin for AsyncTcpSocket
impl UnwindSafe for AsyncTcpSocket
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more