Trait embedded_nal::TcpClientStack[][src]

pub trait TcpClientStack {
    type TcpSocket;
    type Error: Debug;
    fn socket(&mut self) -> Result<Self::TcpSocket, Self::Error>;
fn connect(
        &mut self,
        socket: &mut Self::TcpSocket,
        remote: SocketAddr
    ) -> Result<(), Self::Error>;
fn is_connected(
        &mut self,
        socket: &Self::TcpSocket
    ) -> Result<bool, Self::Error>;
fn send(
        &mut self,
        socket: &mut Self::TcpSocket,
        buffer: &[u8]
    ) -> Result<usize, Self::Error>;
fn receive(
        &mut self,
        socket: &mut Self::TcpSocket,
        buffer: &mut [u8]
    ) -> Result<usize, Self::Error>;
fn close(&mut self, socket: Self::TcpSocket) -> Result<(), Self::Error>; }

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 how write a portable HTTP client which can work with either implementation.

Associated Types

type TcpSocket[src]

The type returned when we create a new TCP socket

type Error: Debug[src]

The type returned when we have an error

Loading content...

Required methods

fn socket(&mut self) -> Result<Self::TcpSocket, Self::Error>[src]

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(
    &mut self,
    socket: &mut Self::TcpSocket,
    remote: SocketAddr
) -> Result<(), Self::Error>
[src]

Connect to the given remote host and port.

Returns Ok if the connection was successful. Otherwise, if the connection could not be completed immediately, this function should return nb::Error::WouldBlock.

fn is_connected(
    &mut self,
    socket: &Self::TcpSocket
) -> Result<bool, Self::Error>
[src]

Check if this socket is connected

fn send(
    &mut self,
    socket: &mut Self::TcpSocket,
    buffer: &[u8]
) -> Result<usize, Self::Error>
[src]

Write to the stream.

Returns the number of bytes written (which may be less than buffer.len()) or an error.

fn receive(
    &mut self,
    socket: &mut Self::TcpSocket,
    buffer: &mut [u8]
) -> Result<usize, Self::Error>
[src]

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. If a packet has not been received when called, then nb::Error::WouldBlock should be returned.

fn close(&mut self, socket: Self::TcpSocket) -> Result<(), Self::Error>[src]

Close an existing TCP socket.

Loading content...

Implementors

impl<'a, T> TcpClientStack for SharedStack<'a, T> where
    T: TcpClientStack
[src]

type TcpSocket = T::TcpSocket

type Error = T::Error

Loading content...