Struct Connection

Source
pub struct Connection<B> { /* private fields */ }
Expand description

Manages the state of a vsock-over-usb connection and the sockets over which data is being transmitted for them.

This implementation aims to be agnostic to both the underlying transport and the buffers used to read and write from it. The buffer type must conform to PacketBuffer, which is essentially a type that holds a mutable slice of bytes and is Send and Unpin-able.

The client of this library will:

Implementations§

Source§

impl<B: PacketBuffer> Connection<B>

Source

pub fn new( control_socket: Socket, incoming_requests_tx: Sender<ConnectionRequest>, ) -> Self

Creates a new connection with:

  • a control_socket, over which data addressed to and from cid 0, port 0 (a control channel between host and device) can be read and written from.
  • An incoming_requests_tx that is the sender half of a request queue for incoming connection requests from the other side.
Source

pub async fn send_empty_echo(&self)

Sends an echo packet to the remote end that you don’t care about the reply, so it doesn’t have a distinct target address or payload.

Source

pub async fn connect( &self, addr: Address, socket: Socket, ) -> Result<ConnectionState, Error>

Starts a connection attempt to the other end of the USB connection, and provides a socket to read and write from. The function will complete when the other end has accepted or rejected the connection, and the returned ConnectionState handle can be used to wait for the connection to be closed.

Source

pub async fn close(&self, address: &Address)

Sends a request for the other end to close the connection.

Source

pub async fn reset(&self, address: &Address) -> Result<(), Error>

Resets the named connection without going through a close request.

Source

pub async fn accept( &self, request: ConnectionRequest, socket: Socket, ) -> Result<ConnectionState, Error>

Accepts a connection for which an outstanding connection request has been made, and provides a socket to read and write data packets to and from. The returned ConnectionState can be used to wait for the connection to be closed.

Source

pub async fn reject(&self, request: ConnectionRequest) -> Result<(), Error>

Rejects a pending connection request from the other side.

Source

pub async fn handle_vsock_packet(&self, packet: Packet<'_>) -> Result<(), Error>

Dispatches the given vsock packet type and handles its effect on any outstanding connections or the overall state of the connection.

Source

pub async fn fill_usb_packet( &self, builder: UsbPacketBuilder<B>, ) -> UsbPacketBuilder<B>

Provides a packet builder for the state machine to write packets to. Returns a future that will be fulfilled when there is data available to send on the packet.

§Panics

Panics if called while another Self::fill_usb_packet future is pending.

Auto Trait Implementations§

§

impl<B> !Freeze for Connection<B>

§

impl<B> !RefUnwindSafe for Connection<B>

§

impl<B> Send for Connection<B>
where B: Send,

§

impl<B> Sync for Connection<B>
where B: Send,

§

impl<B> Unpin for Connection<B>

§

impl<B> !UnwindSafe for Connection<B>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.