Go to file
John Nunley a521cd2c29
breaking: Extract the Events struct and make the Event struct opaque
* Add better documentation for the IOCP module

* Extract Events from Poller

This prevents the need to have an intermediate buffer to read events
from, reducing the need for an allocation and a copy. This is a breaking
change.

* Add event extra information

Foundation for more details later on.

* Add PRI and HUP events
* Fix various failing tests

- Make sure that waitable handles interact properly with the new
  infrastructure
- Fix failing doctests

* Review comments

- Make set_* take a boolean for the value of the flag
- Make Events !Sync
- Fix visibility modifiers
- Inline more methods
- Use a better strategy for testing

* Move completion packets into the Events buffer

This removes one of the mutexes that we have to lock.

* Review comments

Signed-off-by: John Nunley <dev@notgull.net>
2023-08-14 10:03:20 -07:00
.github Allow pinning Rust nightly to concrete version (#132) 2023-08-07 02:24:30 +09:00
examples breaking: Extract the Events struct and make the Event struct opaque 2023-08-14 10:03:20 -07:00
src breaking: Extract the Events struct and make the Event struct opaque 2023-08-14 10:03:20 -07:00
tests breaking: Extract the Events struct and make the Event struct opaque 2023-08-14 10:03:20 -07:00
.cirrus.yml breaking: Rework the API for I/O safety 2023-08-03 20:15:59 -07:00
.gitignore Initial commit 2020-08-06 15:05:24 +02:00
CHANGELOG.md v2.8.0 (#107) 2023-04-20 14:50:12 -07:00
Cargo.toml m: Remove libc from our dependencies 2023-08-13 18:49:43 -07:00
Cross.toml ci: Fix Android breakage (#99) 2023-03-22 11:21:31 -07: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

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.