soio/
lib.rs

1//! A fast IO library for Rust focusing on non-blocking APIs, event
2//! notification, and other useful utilties for building high performance IO
3//! apps.
4//!
5//! ## Usage
6//!
7//! First, add this to your `Cargo.toml`:
8//!
9//! ```toml
10//! [dependencies]
11//! soio = "0.1"
12//! ```
13//!
14//! Then, add this to your crate root:
15//!
16//! ```rust
17//! extern crate soio;
18//! ```
19//!
20//! # Example
21//!
22//! ```
23//! use soio::{Events, Poll, Ready, PollOpt, Token};
24//! use soio::tcp::{TcpListener, TcpStream};
25//!
26//! // Setup some tokens to allow us to identify which event is
27//! // for which socket.
28//! const SERVER: Token = Token(0);
29//! const CLIENT: Token = Token(1);
30//!
31//! // Setup the server socket
32//! let server = TcpListener::bind("127.0.0.1:13265").unwrap();
33//!
34//! // Create an poll instance
35//! let poll = Poll::new().unwrap();
36//!
37//! // Start listening for incoming connections
38//! poll.register(&server, SERVER, Ready::readable(),
39//!               PollOpt::edge()).unwrap();
40//!
41//! // Setup the client socket
42//! let sock = TcpStream::connect("127.0.0.1:13265").unwrap();
43//!
44//! // Register the socket
45//! poll.register(&sock, CLIENT, Ready::readable(),
46//!               PollOpt::edge()).unwrap();
47//!
48//! // Create storage for events
49//! let mut events = Events::with_capacity(1024);
50//!
51//! loop {
52//!     poll.poll(&mut events, None).unwrap();
53//!
54//!     for event in events.iter() {
55//!         match event.token() {
56//!             SERVER => {
57//!                 // Accept and drop the socket immediately, this will close
58//!                 // the socket and notify the client of the EOF.
59//!                 let _ = server.accept();
60//!             }
61//!             CLIENT => {
62//!                 // The server just shuts down the socket, let's just exit
63//!                 // from our event loop.
64//!                 return;
65//!             }
66//!             _ => unreachable!(),
67//!         }
68//!     }
69//! }
70//!
71//! ```
72
73extern crate libc;
74#[macro_use]
75extern crate log;
76
77mod sys;
78mod net;
79mod io;
80mod iovec;
81mod event;
82mod evented;
83mod ready;
84mod poll;
85mod poll_opt;
86mod registration;
87mod token;
88pub mod channel;
89
90
91pub use iovec::IoVec;
92pub use net::{
93    tcp,
94    udp,
95};
96
97pub use event::{
98    Event,
99    Events,
100};
101
102pub use evented::Evented;
103
104pub use ready::Ready;
105
106pub use poll::Poll;
107
108pub use poll_opt::PollOpt;
109
110pub use registration::{
111    Registration,
112    SetReadiness,
113};
114
115pub use token::Token;
116
117pub use sys::EventedFd;