[−][src]Trait drogue_network::tcp::TcpStack
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 implemenation
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
The type returned when we create a new TCP socket
type Error: Into<TcpError> + Debug
The type returned when we have an error
Required methods
fn open(&self, mode: Mode) -> Result<Self::TcpSocket, Self::Error>
Open a new TCP socket. The socket starts in the unconnected state.
fn connect(
&self,
socket: Self::TcpSocket,
remote: HostSocketAddr
) -> Result<Self::TcpSocket, Self::Error>
&self,
socket: Self::TcpSocket,
remote: HostSocketAddr
) -> Result<Self::TcpSocket, Self::Error>
Connect to the given remote host and port.
fn is_connected(&self, socket: &Self::TcpSocket) -> Result<bool, Self::Error>
Check if this socket is connected
fn write(
&self,
socket: &mut Self::TcpSocket,
buffer: &[u8]
) -> Result<usize, Self::Error>
&self,
socket: &mut Self::TcpSocket,
buffer: &[u8]
) -> Result<usize, Self::Error>
Write to the stream. Returns the number of bytes written is returned
(which may be less than buffer.len()
), or an error.
fn read(
&self,
socket: &mut Self::TcpSocket,
buffer: &mut [u8]
) -> Result<usize, Self::Error>
&self,
socket: &mut Self::TcpSocket,
buffer: &mut [u8]
) -> Result<usize, Self::Error>
Read 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(&self, socket: Self::TcpSocket) -> Result<(), Self::Error>
Close an existing TCP socket.