TcpSocket

Struct TcpSocket 

Source
pub struct TcpSocket<const TIMER_HZ: u32, const L: usize> { /* private fields */ }
Expand description

A Transmission Control Protocol socket.

A TCP socket may passively listen for connections or actively connect to another endpoint. Note that, for listening sockets, there is no “backlog”; to be able to simultaneously accept several connections, as many sockets must be allocated, or any new connection attempts will be reset.

Implementations§

Source§

impl<const TIMER_HZ: u32, const L: usize> TcpSocket<TIMER_HZ, L>

Source

pub fn new(socket_id: u8) -> TcpSocket<TIMER_HZ, L>

Create a socket using the given buffers.

Source

pub fn handle(&self) -> SocketHandle

Return the socket handle.

Source

pub fn update_handle(&mut self, handle: SocketHandle)

Source

pub fn endpoint(&self) -> Option<SocketAddr>

Return the bound endpoint.

Source

pub fn state(&self) -> &State<TIMER_HZ>

Return the connection state, in terms of the TCP state machine.

Source

pub fn reset(&mut self)

Source

pub fn should_update_available_data(&mut self, ts: Instant<TIMER_HZ>) -> bool

Source

pub fn recycle(&self, ts: Instant<TIMER_HZ>) -> bool

Source

pub fn closed_by_remote(&mut self, ts: Instant<TIMER_HZ>)

Source

pub fn set_available_data(&mut self, available_data: usize)

Set available data.

Source

pub fn get_available_data(&self) -> usize

Get the number of bytes available to ingress.

Source

pub fn is_connected(&self) -> bool

Return whether a connection is active.

This function returns true if the socket is actively exchanging packets with a remote endpoint. Note that this does not mean that it is possible to send or receive data through the socket; for that, use can_recv.

Source

pub fn may_recv(&self) -> bool

Return whether the receive half of the full-duplex connection is open.

This function returns true if it’s possible to receive data from the remote endpoint. It will return true while there is data in the receive buffer, and if there isn’t, as long as the remote endpoint has not closed the connection.

In terms of the TCP state machine, the socket must be in the Connected, FIN-WAIT-1, or FIN-WAIT-2 state, or have data in the receive buffer instead.

Source

pub fn can_recv(&self) -> bool

Check whether the receive half of the full-duplex connection buffer is open (see may_recv, and the receive buffer is not full.

Source

pub fn recv<'b, F, R>(&'b mut self, f: F) -> Result<R, Error>
where F: FnOnce(&'b mut [u8]) -> (usize, R),

Call f with the largest contiguous slice of octets in the receive buffer, and dequeue the amount of elements returned by f.

This function returns `Err(Error::Illegal) if the receive half of the connection is not open; see may_recv.

Source

pub fn recv_wrapping<'b, F>(&'b mut self, f: F) -> Result<usize, Error>
where F: FnOnce(&'b [u8], Option<&'b [u8]>) -> usize,

Call f with a slice of octets in the receive buffer, and dequeue the amount of elements returned by f.

If the buffer read wraps around, the second argument of f will be Some() with the remainder of the buffer, such that the combined slice of the two arguments, makes up the full buffer.

This function returns `Err(Error::Illegal) if the receive half of the connection is not open; see may_recv.

Source

pub fn recv_slice(&mut self, data: &mut [u8]) -> Result<usize, Error>

Dequeue a sequence of received octets, and fill a slice from it.

This function returns the amount of bytes actually dequeued, which is limited by the amount of free space in the transmit buffer; down to zero.

See also recv.

Source

pub fn peek(&mut self, size: usize) -> Result<&[u8], Error>

Peek at a sequence of received octets without removing them from the receive buffer, and return a pointer to it.

This function otherwise behaves identically to recv.

Source

pub fn rx_window(&self) -> usize

Source

pub fn peek_slice(&mut self, data: &mut [u8]) -> Result<usize, Error>

Peek at a sequence of received octets without removing them from the receive buffer, and fill a slice from it.

This function otherwise behaves identically to recv_slice.

Source

pub fn rx_enqueue_slice(&mut self, data: &[u8]) -> usize

Source

pub fn recv_queue(&self) -> usize

Return the amount of octets queued in the receive buffer.

Note that the Berkeley sockets interface does not have an equivalent of this API.

Source

pub fn set_state(&mut self, state: State<TIMER_HZ>)

Trait Implementations§

Source§

impl<const TIMER_HZ: u32, const L: usize> AnySocket<TIMER_HZ, L> for TcpSocket<TIMER_HZ, L>

Source§

fn downcast( ref_: SocketRef<'_, Socket<TIMER_HZ, L>>, ) -> Result<SocketRef<'_, Self>, Error>

Source§

impl<const TIMER_HZ: u32, const L: usize> Debug for TcpSocket<TIMER_HZ, L>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const TIMER_HZ: u32, const L: usize> Into<Socket<TIMER_HZ, L>> for TcpSocket<TIMER_HZ, L>

Source§

fn into(self) -> Socket<TIMER_HZ, L>

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

§

impl<const TIMER_HZ: u32, const L: usize> Freeze for TcpSocket<TIMER_HZ, L>

§

impl<const TIMER_HZ: u32, const L: usize> RefUnwindSafe for TcpSocket<TIMER_HZ, L>

§

impl<const TIMER_HZ: u32, const L: usize> Send for TcpSocket<TIMER_HZ, L>

§

impl<const TIMER_HZ: u32, const L: usize> Sync for TcpSocket<TIMER_HZ, L>

§

impl<const TIMER_HZ: u32, const L: usize> Unpin for TcpSocket<TIMER_HZ, L>

§

impl<const TIMER_HZ: u32, const L: usize> UnwindSafe for TcpSocket<TIMER_HZ, L>

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<T> Same for T

Source§

type Output = T

Should always be Self
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.