utp/
lib.rs

1//! Implementation of the [Micro Transport Protocol][spec].
2//!
3//! This library provides both a socket interface (`UtpSocket`) and a stream interface
4//! (`UtpStream`).
5//! I recommend that you use `UtpStream`, as it implements the `Read` and `Write`
6//! traits we all know (and love) from `std::io`, which makes it generally easier to work with than
7//! `UtpSocket`.
8//!
9//! [spec]: http://www.bittorrent.org/beps/bep_0029.html
10//!
11//! # Installation
12//!
13//! Ensure your `Cargo.toml` contains:
14//!
15//! ```toml
16//! [dependencies]
17//! utp = "*"
18//! ```
19//!
20//! # Examples
21//!
22//! ```no_run
23//! extern crate utp;
24//!
25//! use utp::UtpStream;
26//! use std::io::Write;
27//!
28//! fn main() {
29//!     // Connect to an hypothetical local server running on port 8080
30//!     let addr = "127.0.0.1:8080";
31//!     let mut stream = UtpStream::connect(addr).expect("Error connecting to remote peer");
32//!
33//!     // Send a string
34//!     stream.write("Hi there!".as_bytes()).expect("Write failed");
35//!
36//!     // Close the stream
37//!     stream.close().expect("Error closing connection");
38//! }
39//! ```
40//!
41//! Note that you can easily convert a socket to a stream using the `Into` trait, like so:
42//!
43//! ```no_run
44//! # use utp::{UtpStream, UtpSocket};
45//! let socket = UtpSocket::bind("0.0.0.0:0").expect("Error binding socket");
46//! let stream: UtpStream = socket.into();
47//! ```
48
49#![deny(missing_docs)]
50
51// Optional features
52#![cfg_attr(feature = "clippy", feature(plugin))]
53#![cfg_attr(feature = "clippy", plugin(clippy))]
54#![cfg_attr(feature = "clippy", allow(len_without_is_empty, doc_markdown, needless_return,
55                                      transmute_ptr_to_ref))]
56#![cfg_attr(feature = "unstable", feature(test))]
57
58extern crate rand;
59extern crate num_traits;
60#[macro_use] extern crate log;
61#[cfg(test)] extern crate quickcheck;
62
63// Public API
64pub use socket::UtpSocket;
65pub use socket::UtpListener;
66pub use stream::UtpStream;
67
68mod bit_iterator;
69mod error;
70mod packet;
71mod socket;
72mod stream;
73mod time;
74mod util;