1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//! A fast, low-level IO library for Rust focusing on non-blocking APIs, event
//! notification, and other useful utilities for building high performance IO
//! apps.
//!
//! # Goals
//!
//! * Fast - minimal overhead over the equivalent OS facilities (epoll, kqueue, etc...)
//! * Zero allocations
//! * A scalable readiness-based API, similar to epoll on Linux
//! * Design to allow for stack allocated buffers when possible (avoid double buffering).
//! * Provide utilities such as a timers, a notification channel, buffer abstractions, and a slab.
//!
//! # Usage
//!
//! Using mio starts by creating an [EventLoop](struct.EventLoop.html), which
//! handles receiving events from the OS and dispatching them to a supplied
//! [Handler](handler/trait.Handler.html).
//!
//! # Example
//!
//! ```
//! use mio::*;
//! use mio::tcp::{TcpListener, TcpStream};
//!
//! // Setup some tokens to allow us to identify which event is
//! // for which socket.
//! const SERVER: Token = Token(0);
//! const CLIENT: Token = Token(1);
//! #
//! # // level() isn't implemented on windows yet
//! # if cfg!(windows) { return }
//!
//! let addr = "127.0.0.1:13265".parse().unwrap();
//!
//! // Setup the server socket
//! let server = TcpListener::bind(&addr).unwrap();
//!
//! // Create an event loop
//! let mut event_loop = EventLoop::new().unwrap();
//!
//! // Start listening for incoming connections
//! event_loop.register(&server, SERVER, EventSet::readable(),
//!                     PollOpt::edge()).unwrap();
//!
//! // Setup the client socket
//! let sock = TcpStream::connect(&addr).unwrap();
//!
//! // Register the socket
//! event_loop.register(&sock, CLIENT, EventSet::readable(),
//!                     PollOpt::edge()).unwrap();
//!
//! // Define a handler to process the events
//! struct MyHandler(TcpListener);
//!
//! impl Handler for MyHandler {
//!     type Timeout = ();
//!     type Message = ();
//!
//!     fn ready(&mut self, event_loop: &mut EventLoop<MyHandler>, token: Token, _: EventSet) {
//!         match token {
//!             SERVER => {
//!                 let MyHandler(ref mut server) = *self;
//!                 // Accept and drop the socket immediately, this will close
//!                 // the socket and notify the client of the EOF.
//!                 let _ = server.accept();
//!             }
//!             CLIENT => {
//!                 // The server just shuts down the socket, let's just
//!                 // shutdown the event loop
//!                 event_loop.shutdown();
//!             }
//!             _ => panic!("unexpected token"),
//!         }
//!     }
//! }
//!
//! // Start handling events
//! event_loop.run(&mut MyHandler(server)).unwrap();
//!
//! ```

#![crate_name = "mio"]
#![cfg_attr(unix, deny(warnings))]

extern crate bytes;
extern crate time;
extern crate slab;
extern crate libc;

#[cfg(unix)]
extern crate nix;

extern crate winapi;
extern crate miow;
extern crate net2;

#[macro_use]
extern crate log;

#[cfg(test)]
extern crate env_logger;

pub mod util;

mod event;
mod event_loop;
mod handler;
mod io;
mod net;
mod notify;
mod poll;
mod sys;
mod timer;
mod token;

pub use event::{
    PollOpt,
    EventSet,
    IoEvent,
};
pub use event_loop::{
    EventLoop,
    EventLoopConfig,
    Sender,
};
pub use handler::{
    Handler,
};
pub use io::{
    TryRead,
    TryWrite,
    Evented,
    TryAccept,
};
pub use net::{
    tcp,
    udp,
    IpAddr,
    Ipv4Addr,
    Ipv6Addr,
};
#[cfg(unix)]
pub mod unix {
    pub use net::unix::{
        pipe,
        PipeReader,
        PipeWriter,
        UnixListener,
        UnixSocket,
        UnixStream,
    };
    pub use sys::{
        EventedFd,
    };
}

pub use notify::{
    NotifyError,
};
pub use poll::{
    Poll,
    Events,
};
pub use timer::{
    Timeout,
    TimerError,
    TimerResult
};
pub use token::{
    Token,
};
#[cfg(unix)]
pub use sys::Io;
pub use sys::Selector;

pub mod prelude {
    pub use super::{
        EventLoop,
        TryRead,
        TryWrite,
    };
}