Struct async_std_utp::UtpSocket[][src]

pub struct UtpSocket {
    pub max_retransmission_retries: u32,
    // some fields omitted
}
Expand description

A structure that represents a uTP (Micro Transport Protocol) connection between a local socket and a remote socket.

The socket will be closed when the value is dropped (either explicitly or when it goes out of scope).

The default maximum retransmission retries is 5, which translates to about 16 seconds. It can be changed by assigning the desired maximum retransmission retries to a socket’s max_retransmission_retries field. Notice that the initial congestion timeout is 500 ms and doubles with each timeout.

Examples

use async_std_utp::UtpSocket;

let mut socket = UtpSocket::bind("127.0.0.1:1234").await.expect("Error binding socket");

let mut buf = vec![0; 1000];
let (amt, _src) = socket.recv_from(&mut buf).await.expect("Error receiving");

let mut buf = &mut buf[..amt];
buf.reverse();
let _ = socket.send_to(buf).await.expect("Error sending");

// Close the socket. You can either call `close` on the socket,
// explicitly drop it or just let it go out of scope.
socket.close().await;
}); }

Fields

max_retransmission_retries: u32

Maximum retransmission retries

Implementations

impl UtpSocket[src]

pub async fn bind<A: ToSocketAddrs>(addr: A) -> Result<UtpSocket>[src]

Creates a new UTP socket from the given address.

The address type can be any implementer of the ToSocketAddr trait. See its documentation for concrete examples.

If more than one valid address is specified, only the first will be used.

pub fn local_addr(&self) -> Result<SocketAddr>[src]

Returns the socket address that this socket was created from.

pub fn peer_addr(&self) -> Result<SocketAddr>[src]

Returns the socket address of the remote peer of this UTP connection.

pub async fn connect<A: ToSocketAddrs>(other: A) -> Result<UtpSocket>[src]

Opens a connection to a remote host by hostname or IP address.

The address type can be any implementer of the ToSocketAddr trait. See its documentation for concrete examples.

If more than one valid address is specified, only the first will be used.

pub async fn close(&mut self) -> Result<()>[src]

Gracefully closes connection to peer.

This method allows both peers to receive all packets still in flight.

pub async fn recv_from(&mut self, buf: &mut [u8]) -> Result<(usize, SocketAddr)>[src]

Receives data from socket.

On success, returns the number of bytes read and the sender’s address. Returns 0 bytes read after receiving a FIN packet when the remaining in-flight packets are consumed.

pub async fn send_to(&mut self, buf: &[u8]) -> Result<usize>[src]

Sends data on the socket to the remote peer. On success, returns the number of bytes written.

pub async fn flush(&mut self) -> Result<()>[src]

Consumes acknowledgements for every pending packet.

Trait Implementations

impl Debug for UtpSocket[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl Drop for UtpSocket[src]

fn drop(&mut self)[src]

Executes the destructor for this type. Read more

impl From<UtpSocket> for UtpStream[src]

fn from(socket: UtpSocket) -> Self[src]

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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.

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

Performs the conversion.

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.

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

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V