[−][src]Struct async_resol_vbus::TcpServerHandshake
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]
&'_ mut self,
validator: V
) -> Result<T> where
V: Fn(String, Option<String>) -> R,
R: Future<Output = Result<T, &'static str>>,
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. Thevalue
is used to resolve thereceive_command
Future
.Err(reply)
if the validation failed. Thereply
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]
&'_ mut self,
validator: V
) -> Result<String> where
V: Fn(String) -> R,
R: Future<Output = Result<String, &'static str>>,
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]
&'_ mut self,
validator: V
) -> Result<String> where
V: Fn(String) -> R,
R: Future<Output = Result<String, &'static str>>,
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]
&'_ mut self,
validator: V
) -> Result<u8> where
V: Fn(u8) -> R,
R: Future<Output = Result<u8, &'static str>>,
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
Auto Trait Implementations
impl RefUnwindSafe for TcpServerHandshake
impl Send for TcpServerHandshake
impl Sync for TcpServerHandshake
impl Unpin for TcpServerHandshake
impl UnwindSafe for TcpServerHandshake
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,