Struct ublox_sockets::tcp::TcpSocket
source · [−]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
sourceimpl<const TIMER_HZ: u32, const L: usize> TcpSocket<TIMER_HZ, L>
impl<const TIMER_HZ: u32, const L: usize> TcpSocket<TIMER_HZ, L>
sourcepub fn handle(&self) -> SocketHandle
pub fn handle(&self) -> SocketHandle
Return the socket handle.
pub fn update_handle(&mut self, handle: SocketHandle)
sourcepub fn endpoint(&self) -> Option<SocketAddr>
pub fn endpoint(&self) -> Option<SocketAddr>
Return the bound endpoint.
sourcepub fn state(&self) -> &State<TIMER_HZ>
pub fn state(&self) -> &State<TIMER_HZ>
Return the connection state, in terms of the TCP state machine.
pub fn reset(&mut self)
pub fn should_update_available_data(&mut self, ts: Instant<TIMER_HZ>) -> bool
pub fn recycle(&self, ts: Instant<TIMER_HZ>) -> bool
pub fn closed_by_remote(&mut self, ts: Instant<TIMER_HZ>)
sourcepub fn set_available_data(&mut self, available_data: usize)
pub fn set_available_data(&mut self, available_data: usize)
Set available data.
sourcepub fn get_available_data(&self) -> usize
pub fn get_available_data(&self) -> usize
Get the number of bytes available to ingress.
sourcepub fn is_connected(&self) -> bool
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.
sourcepub fn may_recv(&self) -> bool
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.
sourcepub fn can_recv(&self) -> bool
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.
sourcepub fn recv<'b, F, R>(&'b mut self, f: F) -> Result<R, Error>where
F: FnOnce(&'b mut [u8]) -> (usize, R),
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.
sourcepub fn recv_wrapping<'b, F>(&'b mut self, f: F) -> Result<usize, Error>where
F: FnOnce(&'b [u8], Option<&'b [u8]>) -> usize,
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.
sourcepub fn recv_slice(&mut self, data: &mut [u8]) -> Result<usize, Error>
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.
sourcepub fn peek(&mut self, size: usize) -> Result<&[u8], Error>
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.
pub fn rx_window(&self) -> usize
sourcepub fn peek_slice(&mut self, data: &mut [u8]) -> Result<usize, Error>
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.
pub fn rx_enqueue_slice(&mut self, data: &[u8]) -> usize
sourcepub fn recv_queue(&self) -> usize
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.