[][src]Struct async_resol_vbus::TcpServerHandshake

pub struct TcpServerHandshake { /* fields omitted */ }

Handles the server-side of the VBus-over-TCP handshake.

Examples

use async_std::net::{SocketAddr, TcpListener, TcpStream};

use async_resol_vbus::TcpServerHandshake;

let address = "0.0.0.0:7053".parse::<SocketAddr>()?;
let listener = TcpListener::bind(address).await?;
let (stream, _) = listener.accept().await?;
let mut hs = TcpServerHandshake::start(stream).await?;
let password = hs.receive_pass_command().await?;
// ...
let stream = hs.receive_data_command().await?;
// ...

Methods

impl TcpServerHandshake[src]

pub async fn start(stream: TcpStream) -> Result<TcpServerHandshake>[src]

Start the VBus-over-TCP handshake as the server side.

pub fn into_inner(self) -> TcpStream[src]

Consume self and return the underlying TcpStream.

pub async fn receive_command<'_, V, R, T>(
    &'_ mut self,
    validator: V
) -> Result<T> where
    V: Fn(String, Option<String>) -> R,
    R: Future<Output = Result<T, &'static str>>, 
[src]

Receive a command and verify it and its provided arguments. The command reception is repeated as long as the verification fails.

The preferred way to receive commands documented in the VBus-over-TCP specification is through the receive_xxx_command and receive_xxx_command_and_verify_yyy methods which use the receive_command method internally.

This method takes a validator function that is called with the received command and its optional arguments. The validator returns a Future that can resolve into an std::result::Result<T, &'static str>. It can either be:

  • Ok(value) if the validation succeeded. The value is used to resolve the receive_command Future.
  • Err(reply) if the validation failed. The reply is send back to the client and the command reception is repeated.

pub async fn receive_connect_command<'_>(&'_ mut self) -> Result<String>[src]

Wait for a CONNECT <via_tag> command. The via tag argument is returned.

pub async fn receive_connect_command_and_verify_via_tag<'_, V, R>(
    &'_ mut self,
    validator: V
) -> Result<String> where
    V: Fn(String) -> R,
    R: Future<Output = Result<String, &'static str>>, 
[src]

Wait for a CONNECT <via_tag> command.

pub async fn receive_pass_command<'_>(&'_ mut self) -> Result<String>[src]

Wait for a PASS <password> command.

pub async fn receive_pass_command_and_verify_password<'_, V, R>(
    &'_ mut self,
    validator: V
) -> Result<String> where
    V: Fn(String) -> R,
    R: Future<Output = Result<String, &'static str>>, 
[src]

Wait for a PASS <password> command and validate the provided password.

pub async fn receive_channel_command<'_>(&'_ mut self) -> Result<u8>[src]

Wait for a CHANNEL <channel> command.

pub async fn receive_channel_command_and_verify_channel<'_, V, R>(
    &'_ mut self,
    validator: V
) -> Result<u8> where
    V: Fn(u8) -> R,
    R: Future<Output = Result<u8, &'static str>>, 
[src]

Wait for CHANNEL <channel> command and validate the provided channel

pub async fn receive_data_command(__arg0: Self) -> Result<TcpStream>[src]

Wait for a DATA command.

This function returns the underlying TcpStream since the handshake is complete after sending this command.

Trait Implementations

impl Debug for TcpServerHandshake[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.