Skip to main content

TimestampedTcpSocket

Struct TimestampedTcpSocket 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl AsRawFd for TimestampedTcpSocket

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Deref for TimestampedTcpSocket

Source§

type Target = i32

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Drop for TimestampedTcpSocket

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl From<&mut i32> for TimestampedTcpSocket

Source§

fn from(value: &mut i32) -> Self

Converts to this type from the input type.
Source§

impl Socket<TimestampedTcpSocket> for TimestampedTcpSocket

Source§

unsafe fn from_raw_fd(fd: RawFd) -> TimestampedTcpSocket

Creates a new instance of the socket from the given raw file descriptor. Read more
Source§

fn send(&self, message: impl BeBytes) -> Result<(isize, DateTime), CommonError>

Sends the given message over the socket. Read more
Source§

fn send_to( &self, _address: &SocketAddr, message: impl BeBytes, ) -> Result<(isize, DateTime), CommonError>

Sends the given message to the specified socket address. Read more
Source§

fn receive(&self, buffer: &mut [u8]) -> Result<(isize, DateTime), CommonError>

Receives data from the socket into the given buffer. Read more
Source§

fn receive_from( &self, buffer: &mut [u8], ) -> Result<(isize, SocketAddr, DateTime), CommonError>

Receives data from the socket into the given buffer, along with the address of the sender. Read more
Source§

fn set_socket_options( &mut self, level: i32, name: i32, value: Option<i32>, ) -> Result<i32, CommonError>

Source§

fn set_fcntl_options(&self) -> Result<i32, CommonError>

Source§

fn set_timestamping_options(&mut self) -> Result<i32, CommonError>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.