pub struct TimestampedTcpSocket { /* private fields */ }Expand description
A TCP socket wrapper that includes the raw file descriptor.
This structure is intended to wrap the raw file descriptor provided by a
TCP socket and includes some common socket operations like bind, listen,
accept, and connect. It also provides timestamped send and receive operations.
§Safety
This structure performs raw system calls via the libc crate. Incorrect use could lead to system errors. Ensure the correct use of these system calls in accordance with POSIX standards.
Implementations§
Source§impl TimestampedTcpSocket
impl TimestampedTcpSocket
Sourcepub fn new(socket: RawFd) -> Self
pub fn new(socket: RawFd) -> Self
Create a new instance of TimestampedTcpSocket from a raw file descriptor.
This method sets the SO_REUSEADDR option on the socket to allow the reuse
of local addresses.
§Safety
The provided file descriptor should be valid and correspond to a socket.
Sourcepub fn bind(addr: &SocketAddr) -> Result<Self, CommonError>
pub fn bind(addr: &SocketAddr) -> Result<Self, CommonError>
Binds the socket to a specific address.
The socket will be available for incoming connection attempts on the
specified addr.
§Errors
This method returns an error if the socket cannot be bound to the provided address.
Sourcepub fn listen(&self, backlog: i32) -> Result<(), CommonError>
pub fn listen(&self, backlog: i32) -> Result<(), CommonError>
Listen for incoming connections.
The backlog parameter defines the maximum number of pending connections.
§Errors
This method returns an error if the socket cannot be set to listen mode.
Sourcepub fn accept(&self) -> Result<(TimestampedTcpSocket, SocketAddr), CommonError>
pub fn accept(&self) -> Result<(TimestampedTcpSocket, SocketAddr), CommonError>
Accept a new incoming connection attempt.
This method blocks until a connection attempt is made to the socket.
§Returns
This method returns a new TimestampedTcpSocket for the incoming connection
and the address of the peer socket.
§Errors
This method returns an error if an incoming connection cannot be accepted.
Sourcepub fn connect(&mut self, addr: SocketAddr) -> Result<i32, CommonError>
pub fn connect(&mut self, addr: SocketAddr) -> Result<i32, CommonError>
Connect to a remote socket at the provided address.
This method blocks until the connection is established.
§Errors
This method returns an error if the connection attempt fails.