Struct utp::UtpStream [] [src]

pub struct UtpStream {
    // some fields omitted
}

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]);

Methods

impl UtpStream
[src]

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.

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.

fn close(&mut self) -> Result<()>

Gracefully closes connection to peer.

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

fn local_addr(&self) -> Result<SocketAddr>

Returns the socket address of the local half of this uTP connection.

fn set_max_retransmission_retries(&mut self, n: u32)

Changes the maximum number of retransmission retries on the underlying socket.

Methods from Deref<Target=UtpSocket>

fn local_addr(&self) -> Result<SocketAddr>

Returns the socket address that this socket was created from.

fn peer_addr(&self) -> Result<SocketAddr>

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

fn close(&mut self) -> Result<()>

Gracefully closes connection to peer.

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

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

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.

fn set_read_timeout(&mut self, user_timeout: Option<i64>)

Changes read operations to block for at most the specified number of milliseconds.

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

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

fn flush(&mut self) -> Result<()>

Consumes acknowledgements for every pending packet.

Trait Implementations

impl Read for UtpStream
[src]

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usizeError>
1.0.0

Read all bytes until EOF in this source, placing them into buf. Read more

fn read_to_string(&mut self, buf: &mut String) -> Result<usizeError>
1.0.0

Read all bytes until EOF in this source, placing them into buf. Read more

fn read_exact(&mut self, buf: &mut [u8]) -> Result<()Error>
1.6.0

Read the exact number of bytes required to fill buf. Read more

fn by_ref(&mut self) -> &mut Self
1.0.0

Creates a "by reference" adaptor for this instance of Read. Read more

fn bytes(self) -> Bytes<Self>
1.0.0

Transforms this Read instance to an Iterator over its bytes. Read more

fn chars(self) -> Chars<Self>

Unstable (io)

: the semantics of a partial read/write of where errors happen is currently unclear and may change

Transforms this Read instance to an Iterator over chars. Read more

fn chain<R>(self, next: R) -> Chain<Self, R> where R: Read
1.0.0

Creates an adaptor which will chain this stream with another. Read more

fn take(self, limit: u64) -> Take<Self>
1.0.0

Creates an adaptor which will read at most limit bytes from it. Read more

impl Write for UtpStream
[src]

fn write(&mut self, buf: &[u8]) -> Result<usize>

Write a buffer into this object, returning how many bytes were written. Read more

fn flush(&mut self) -> Result<()>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more

fn write_all(&mut self, buf: &[u8]) -> Result<()Error>
1.0.0

Attempts to write an entire buffer into this write. Read more

fn write_fmt(&mut self, fmt: Arguments) -> Result<()Error>
1.0.0

Writes a formatted string into this writer, returning any error encountered. Read more

fn by_ref(&mut self) -> &mut Self
1.0.0

Creates a "by reference" adaptor for this instance of Write. Read more

impl Deref for UtpStream
[src]

type Target = UtpSocket

The resulting type after dereferencing

fn deref(&self) -> &UtpSocket

The method called to dereference a value