Trait embedded_nal_async::TcpClientStack
source · [−]pub trait TcpClientStack {
type TcpSocket;
type Error: Debug;
type SocketFuture<'m>: Future<Output = Result<Self::TcpSocket, Self::Error>> + 'm
where
Self: 'm;
type ConnectFuture<'m>: Future<Output = Result<(), Self::Error>> + 'm
where
Self: 'm;
type IsConnectedFuture<'m>: Future<Output = Result<bool, Self::Error>> + 'm
where
Self: 'm;
type SendFuture<'m>: Future<Output = Result<usize, Self::Error>> + 'm
where
Self: 'm;
type ReceiveFuture<'m>: Future<Output = Result<usize, Self::Error>> + 'm
where
Self: 'm;
type CloseFuture<'m>: Future<Output = Result<(), Self::Error>> + 'm
where
Self: 'm;
fn socket<'m>(&'m mut self) -> Self::SocketFuture<'m>;
fn connect<'m>(
&'m mut self,
socket: &'m mut Self::TcpSocket,
remote: SocketAddr
) -> Self::ConnectFuture<'m>;
fn is_connected<'m>(
&'m mut self,
socket: &'m Self::TcpSocket
) -> Self::IsConnectedFuture<'m>;
fn send<'m>(
&'m mut self,
socket: &'m mut Self::TcpSocket,
buffer: &'m [u8]
) -> Self::SendFuture<'m>;
fn receive<'m>(
&'m mut self,
socket: &'m mut Self::TcpSocket,
buffer: &'m mut [u8]
) -> Self::ReceiveFuture<'m>;
fn close<'m>(&'m mut self, socket: Self::TcpSocket) -> Self::CloseFuture<'m>;
}Expand description
This trait is implemented by TCP/IP stacks. You could, for example, have an implementation
which knows how to send AT commands to an ESP8266 WiFi module. You could have another implementation
which knows how to driver the Rust Standard Library’s std::net module. Given this trait, you can
write a portable HTTP client which can work with either implementation.
Required Associated Types
Future returned by socket function.
Future returned by connect function.
Future returned by is_connected function.
Future returned by send function.
Future returned by receive function.
Required Methods
fn socket<'m>(&'m mut self) -> Self::SocketFuture<'m>
fn socket<'m>(&'m mut self) -> Self::SocketFuture<'m>
Open a socket for usage as a TCP client.
The socket must be connected before it can be used.
Returns Ok(socket) if the socket was successfully created.
fn connect<'m>(
&'m mut self,
socket: &'m mut Self::TcpSocket,
remote: SocketAddr
) -> Self::ConnectFuture<'m>
fn connect<'m>(
&'m mut self,
socket: &'m mut Self::TcpSocket,
remote: SocketAddr
) -> Self::ConnectFuture<'m>
Connect to the given remote host and port.
Returns Ok if the connection was successful.
fn is_connected<'m>(
&'m mut self,
socket: &'m Self::TcpSocket
) -> Self::IsConnectedFuture<'m>
fn is_connected<'m>(
&'m mut self,
socket: &'m Self::TcpSocket
) -> Self::IsConnectedFuture<'m>
Check if this socket is connected
Write to the stream.
Returns the number of bytes written (which may be less than buffer.len()) or an error.
Receive data from the stream.
Returns Ok(n), which means n bytes of data have been received and
they have been placed in &buffer[0..n], or an error.
fn close<'m>(&'m mut self, socket: Self::TcpSocket) -> Self::CloseFuture<'m>
fn close<'m>(&'m mut self, socket: Self::TcpSocket) -> Self::CloseFuture<'m>
Close an existing TCP socket.