Go to file
Stjepan Glavina d106cef8c4 Bump to v0.1.6 2020-08-29 17:34:45 +02:00
.github Initial commit 2020-08-06 15:05:24 +02:00
examples Document non-blocking mode 2020-08-08 10:20:19 +02:00
src Bump to v0.1.6 2020-08-29 17:34:45 +02:00
tests Fix warnings 2020-08-15 09:12:45 +02:00
.gitignore Initial commit 2020-08-06 15:05:24 +02:00
CHANGELOG.md Bump to v0.1.6 2020-08-29 17:34:45 +02:00
Cargo.toml Bump to v0.1.6 2020-08-29 17:34:45 +02:00
LICENSE-APACHE Initial commit 2020-08-06 15:05:24 +02:00
LICENSE-MIT Initial commit 2020-08-06 15:05:24 +02:00
README.md Merge pull request #1 from GuillaumeGomez/doc-comment 2020-08-13 20:58:13 +02:00

README.md

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")?;
let key = 7; // arbitrary key identifying the socket

// Create a poller and register interest in readability on the socket.
let poller = Poller::new()?;
poller.insert(&socket)?;
poller.interest(&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.interest(&socket, Event::readable(key))?;
        }
    }
}
std::io::Result::Ok(())

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.