Go to file
John Nunley 24900fb662
m(windows): Reimplement Wepoll in Rust (#88)
Reimplements the C-based wepoll backend in Rust, using some handwritten code. This PR also implements bindings to the I/O Completion Ports and \Device\Afd APIs. For more information on the latter, see my blog post on the subject: https://notgull.github.io/device-afd/

Note that the IOCP API is wrapped using a `Pin`-oriented "CompletionHandle" system that is relatively brittle. This should be replaced with a better model when one becomes available.
2023-03-05 16:25:25 -08:00
.github Fix Dragonfly BSD CI 2023-03-04 15:35:17 +09:00
examples feat: Expose other kqueue filters (#83) 2023-02-03 11:14:33 -08:00
src m(windows): Reimplement Wepoll in Rust (#88) 2023-03-05 16:25:25 -08:00
tests m(windows): Reimplement Wepoll in Rust (#88) 2023-03-05 16:25:25 -08:00
.cirrus.yml Test more Windows targets on CI 2023-03-04 15:35:17 +09:00
.gitignore Initial commit 2020-08-06 15:05:24 +02:00
CHANGELOG.md Release 2.5.2 (#58) 2022-12-13 12:26:59 +09:00
Cargo.toml m(windows): Reimplement Wepoll in Rust (#88) 2023-03-05 16:25:25 -08: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 m(windows): Reimplement Wepoll in Rust (#88) 2023-03-05 16:25:25 -08:00
build.rs Add error message for Wepoll (#54) 2022-11-30 20:26:28 -08:00

README.md

polling

Build License Cargo Documentation

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

Supported platforms:

  • epoll: Linux, Android
  • kqueue: macOS, iOS, tvOS, watchOS, FreeBSD, NetBSD, OpenBSD, DragonFly BSD
  • event ports: illumos, Solaris
  • poll: VxWorks, Fuchsia, other Unix systems
  • IOCP: Windows, Wine (version 7.13+)

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.