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 and return the connected stream.
The returned TcpStream must be used for subsequent I/O.
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_reuseport(&self, on: bool) -> Result<()>
pub fn set_reuseport(&self, on: bool) -> Result<()>
Set the socket port reuse option where supported.
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_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 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.