pub struct TcpSocket { /* private fields */ }
Expand description
Implementations§
source§impl TcpSocket
impl TcpSocket
sourcepub fn local_addr(&self) -> AxResult<SocketAddr>
pub fn local_addr(&self) -> AxResult<SocketAddr>
Returns the local address and port, or
Err(NotConnected)
if not connected.
sourcepub fn peer_addr(&self) -> AxResult<SocketAddr>
pub fn peer_addr(&self) -> AxResult<SocketAddr>
Returns the remote address and port, or
Err(NotConnected)
if not connected.
sourcepub fn is_nonblocking(&self) -> bool
pub fn is_nonblocking(&self) -> bool
Returns whether this socket is in nonblocking mode.
sourcepub fn set_nonblocking(&self, nonblocking: bool)
pub fn set_nonblocking(&self, nonblocking: bool)
Moves this TCP stream into or out of nonblocking mode.
This will result in read
, write
, recv
and send
operations
becoming nonblocking, i.e., immediately returning from their calls.
If the IO operation is successful, Ok
is returned and no further
action is required. If the IO operation could not be completed and needs
to be retried, an error with kind Err(WouldBlock)
is
returned.
sourcepub fn connect(&self, remote_addr: SocketAddr) -> AxResult
pub fn connect(&self, remote_addr: SocketAddr) -> AxResult
Connects to the given address and port.
The local port is generated automatically.
sourcepub fn bind(&self, local_addr: SocketAddr) -> AxResult
pub fn bind(&self, local_addr: SocketAddr) -> AxResult
sourcepub fn close(&mut self)
pub fn close(&mut self)
Close the transmit half of the tcp socket.
It will call close()
on smoltcp::socket::tcp::Socket. It should send FIN to remote half.
This function is for shutdown(fd, SHUT_WR) syscall.
It won’t change TCP state. It won’t affect unconnected sockets (listener).
sourcepub fn recv(&self, buf: &mut [u8]) -> AxResult<usize>
pub fn recv(&self, buf: &mut [u8]) -> AxResult<usize>
Receives data from the socket, stores it in the given buffer.
sourcepub fn recv_timeout(&self, buf: &mut [u8], ticks: u64) -> AxResult<usize>
pub fn recv_timeout(&self, buf: &mut [u8], ticks: u64) -> AxResult<usize>
Receives data from the socket, stores it in the given buffer.
It will return Err(Timeout)
if expired.
sourcepub fn set_nagle_enabled(&self, enabled: bool) -> AxResult
pub fn set_nagle_enabled(&self, enabled: bool) -> AxResult
To set the nagle algorithm enabled or not.
sourcepub fn nagle_enabled(&self) -> bool
pub fn nagle_enabled(&self) -> bool
To get the nagle algorithm enabled or not.
sourcepub fn with_socket<R>(&self, f: impl FnOnce(Option<&Socket<'_>>) -> R) -> R
pub fn with_socket<R>(&self, f: impl FnOnce(Option<&Socket<'_>>) -> R) -> R
To get the socket and call the given function.
If the socket is not connected, it will return None.
Or it will return the result of the given function.
sourcepub fn with_socket_mut<R>(
&mut self,
f: impl FnOnce(Option<&mut Socket<'_>>) -> R
) -> R
pub fn with_socket_mut<R>( &mut self, f: impl FnOnce(Option<&mut Socket<'_>>) -> R ) -> R
To get the mutable socket and call the given function.
If the socket is not connected, it will return None.
Or it will return the result of the given function.