pub struct UtpStream { /* private fields */ }
Expand description
A structure that represents a uTP (Micro Transport Protocol) stream between a local socket and a remote socket.
The connection 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 calling set_max_retransmission_retries
. Notice that the initial congestion timeout
is 500 ms and doubles with each timeout.
§Examples
use utp::UtpStream;
use std::io::{Read, Write};
let mut stream = UtpStream::bind("127.0.0.1:1234").expect("Error binding stream");
let _ = stream.write(&[1]);
let _ = stream.read(&mut [0; 1000]);
Implementations§
Source§impl UtpStream
impl UtpStream
Sourcepub fn bind<A: ToSocketAddrs>(addr: A) -> Result<UtpStream>
pub fn bind<A: ToSocketAddrs>(addr: A) -> Result<UtpStream>
Creates a uTP stream listening on 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.
Sourcepub fn connect<A: ToSocketAddrs>(dst: A) -> Result<UtpStream>
pub fn connect<A: ToSocketAddrs>(dst: A) -> Result<UtpStream>
Opens a uTP 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.
Sourcepub fn close(&mut self) -> Result<()>
pub fn close(&mut self) -> Result<()>
Gracefully closes connection to peer.
This method allows both peers to receive all packets still in flight.
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Returns the socket address of the local half of this uTP connection.
Sourcepub fn set_max_retransmission_retries(&mut self, n: u32)
pub fn set_max_retransmission_retries(&mut self, n: u32)
Changes the maximum number of retransmission retries on the underlying socket.
Sourcepub fn send_keepalive(&mut self)
pub fn send_keepalive(&mut self)
Try to send a keepalive packet to the peer, ensuring the connection stays active.
Methods from Deref<Target = UtpSocket>§
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Returns the socket address that this socket was created from.
Sourcepub fn peer_addr(&self) -> Result<SocketAddr>
pub fn peer_addr(&self) -> Result<SocketAddr>
Returns the socket address of the remote peer of this UTP connection.
Trait Implementations§
Source§impl Read for UtpStream
impl Read for UtpStream
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moreSource§impl Write for UtpStream
impl Write for UtpStream
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)