pub struct TcpSocket { /* private fields */ }Expand description
Low level synchronous TCP socket.
Implementations§
Source§impl TcpSocket
impl TcpSocket
Sourcepub fn from_config(config: &TcpConfig) -> Result<Self>
pub fn from_config(config: &TcpConfig) -> Result<Self>
Build a socket according to TcpSocketConfig.
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 fn bind(&self, addr: SocketAddr) -> Result<()>
pub fn bind(&self, addr: SocketAddr) -> Result<()>
Bind the socket to a specific address.
Sourcepub fn connect(&self, addr: SocketAddr) -> Result<()>
pub fn connect(&self, addr: SocketAddr) -> Result<()>
Connect to a remote address.
Sourcepub fn connect_timeout(
&self,
target: SocketAddr,
timeout: Duration,
) -> Result<TcpStream>
pub fn connect_timeout( &self, target: SocketAddr, timeout: Duration, ) -> Result<TcpStream>
Connect to the target address with a timeout.
Sourcepub fn accept(&self) -> Result<(TcpStream, SocketAddr)>
pub fn accept(&self) -> Result<(TcpStream, SocketAddr)>
Accept an incoming connection.
Sourcepub fn to_tcp_stream(self) -> Result<TcpStream>
pub fn to_tcp_stream(self) -> Result<TcpStream>
Convert the socket into a TcpStream.
Sourcepub fn to_tcp_listener(self) -> Result<TcpListener>
pub fn to_tcp_listener(self) -> Result<TcpListener>
Convert the socket into a TcpListener.
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 packet (for RAW TCP use).
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 packet (for RAW TCP use).
Sourcepub fn set_reuseaddr(&self, on: bool) -> Result<()>
pub fn set_reuseaddr(&self, on: bool) -> Result<()>
Set the socket to reuse the address.
Sourcepub fn set_nodelay(&self, on: bool) -> Result<()>
pub fn set_nodelay(&self, on: bool) -> Result<()>
Set the socket to not delay packets.
Sourcepub fn set_linger(&self, dur: Option<Duration>) -> Result<()>
pub fn set_linger(&self, dur: Option<Duration>) -> Result<()>
Set the 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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TcpSocket
impl RefUnwindSafe for TcpSocket
impl Send for TcpSocket
impl Sync for TcpSocket
impl Unpin for TcpSocket
impl UnwindSafe for TcpSocket
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