[][src]Struct tokio_resol_vbus::TcpServerHandshake

pub struct TcpServerHandshake { /* fields omitted */ }

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

Examples

This example simulates a RESOL DL2 by accepting TCP connections on port 7053, requiring the client to provide a password and then switch the connection into raw VBus data mode.

use tokio::prelude::*;
use tokio::net::TcpListener;
use tokio_resol_vbus::TcpServerHandshake;

let addr = "127.0.0.1:7053".parse().expect("Unable to parse address");
let listener = TcpListener::bind(&addr).expect("Unable to bind listener");

let server = listener
    .incoming()
    .map_err(|err| eprintln!("{}", err))
    .for_each(|socket| {
        let conn = TcpServerHandshake::start(socket)
            .and_then(|hs| hs.receive_pass_command_and_verify_password(|password| {
                if password == "vbus" {
                    Ok(Some(password))
                } else {
                    Ok(None)
                }
            }))
            .and_then(|(hs, _)| hs.receive_data_command())
            .and_then(|socket| {
                // do something with the socket
            })
            .map_err(|err| eprintln!("Server error: {}", err));
        tokio::spawn(conn)
    });

tokio::run(server);

Methods

impl TcpServerHandshake
[src]

Start the VBus-over-TCP handshake as the client side connecting to a server.

Consume self and return the underlying TcpStream.

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.

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

Wait for a CONNECT <via_tag> command.

Wait for a PASS <password> command.

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

Wait for a CHANNEL <channel> command.

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

Wait for a DATA command.

Trait Implementations

impl Debug for TcpServerHandshake
[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From for T
[src]

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

impl<T> Erased for T