Struct mio::Poll [] [src]

pub struct Poll {
    // some fields omitted
}

Polls for readiness events on all registered values.

The Poll type acts as an interface allowing a program to wait on a set of IO handles until one or more become "ready" to be operated on. An IO handle is considered ready to operate on when the given operation can complete without blocking.

To use Poll, an IO handle must first be registered with the Poll instance using the register() handle. An Ready representing the program's interest in the socket is specified as well as an arbitrary Token which is used to identify the IO handle in the future.

Edge-triggered and level-triggered

An IO handle registration may request edge-triggered notifications or level-triggered notifications. This is done by specifying the PollOpt argument to register() and reregister().

Portability

Cross platform portability is provided for Mio's TCP & UDP implementations.

Examples

use mio::*;
use mio::tcp::*;

// Construct a new `Poll` handle as well as the `Events` we'll store into
let mut poll = Poll::new().unwrap();
let mut events = Events::with_capacity(1024);

// Connect the stream
let stream = TcpStream::connect(&"173.194.33.80:80".parse().unwrap()).unwrap();

// Register the stream with `Poll`
poll.register(&stream, Token(0), Ready::all(), PollOpt::edge()).unwrap();

// Wait for the socket to become ready
poll.poll(&mut events, None).unwrap();

Methods

impl Poll

fn new() -> Result<Poll>

Return a new Poll handle using a default configuration.

fn register<E: ?Sized>(&self, io: &E, token: Token, interest: Ready, opts: PollOpt) -> Result<()> where E: Evented

Register an Evented handle with the Poll instance.

fn reregister<E: ?Sized>(&self, io: &E, token: Token, interest: Ready, opts: PollOpt) -> Result<()> where E: Evented

Re-register an Evented handle with the Poll instance.

fn deregister<E: ?Sized>(&self, io: &E) -> Result<()> where E: Evented

Deregister an Evented handle with the Poll instance.

fn poll(&self, events: &mut Events, timeout: Option<Duration>) -> Result<usize>

Block the current thread and wait until any Evented values registered with the Poll instance are ready or the given timeout has elapsed.

Trait Implementations

impl Debug for Poll

fn fmt(&self, fmt: &mut Formatter) -> Result