#mio #epoll #kqueue #iocp #wepoll

polling

Portable interface to epoll, kqueue, event ports, and wepoll

18 releases (8 stable)

2.0.2 Oct 18, 2020
2.0.1 Oct 9, 2020
1.1.0 Sep 20, 2020
0.1.9 Sep 6, 2020
0.1.6 Aug 29, 2020

#423 in Asynchronous

Download history 41999/week @ 2020-11-02 41082/week @ 2020-11-09 46938/week @ 2020-11-16 42512/week @ 2020-11-23 45890/week @ 2020-11-30 47041/week @ 2020-12-07 48864/week @ 2020-12-14 34695/week @ 2020-12-21 31831/week @ 2020-12-28 49395/week @ 2021-01-04 57905/week @ 2021-01-11 55778/week @ 2021-01-18 60448/week @ 2021-01-25 64871/week @ 2021-02-01 60759/week @ 2021-02-08 62792/week @ 2021-02-15

91,396 downloads per month
Used in 964 crates (4 directly)

Apache-2.0 OR MIT

47KB
873 lines

polling

Build License Cargo Documentation

Portable interface to epoll, kqueue, event ports, and wepoll.

Supported platforms:

Polling is done in oneshot mode, which means interest in I/O events needs to be reset after an event is delivered if we're interested in the next event of the same kind.

Only one thread can be waiting for I/O events at a time.

Examples

use polling::{Event, Poller};
use std::net::TcpListener;

// Create a TCP listener.
let socket = TcpListener::bind("127.0.0.1:8000")?;
socket.set_nonblocking(true)?;
let key = 7; // Arbitrary key identifying the socket.

// Create a poller and register interest in readability on the socket.
let poller = Poller::new()?;
poller.add(&socket, Event::readable(key))?;

// The event loop.
let mut events = Vec::new();
loop {
    // Wait for at least one I/O event.
    events.clear();
    poller.wait(&mut events, None)?;

    for ev in &events {
        if ev.key == key {
            // Perform a non-blocking accept operation.
            socket.accept()?;
            // Set interest in the next readability event.
            poller.modify(&socket, Event::readable(key))?;
        }
    }
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~140KB