Go to file
John Nunley 0b4afcaf0a
ci: Remove +nightly and use default
Previously in the "cross" CI job, checks would use "+nightly" to ensure
that the nightly compiler is used. However this adds a lot of noise. In
order to clean up CI this commit replaces "+nightly" with "rustup
default nightly" at the start of the job.

cc https://github.com/smol-rs/polling/pull/197#discussion_r1573375732

Signed-off-by: John Nunley <dev@notgull.net>
2024-04-22 18:36:07 -07:00
.github ci: Remove +nightly and use default 2024-04-22 18:36:07 -07:00
examples feat: Replace is_connect_failed with is_err 2024-03-20 22:04:46 -07:00
src feat: ported to Vita target 2024-04-20 11:22:46 -07:00
tests feat: ported to Vita target 2024-04-20 11:22:46 -07:00
.cirrus.yml ci: Update FreeBSD image to 13.2 2024-01-07 16:11:02 +09:00
.gitignore Initial commit 2020-08-06 15:05:24 +02:00
CHANGELOG.md v3.7.0 2024-04-22 16:33:52 -07:00
Cargo.toml v3.7.0 2024-04-22 16:33:52 -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 feat: Add support for HermitOS 2024-03-12 21:33:06 -07:00

README.md

polling

Build License Cargo Documentation

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

Supported platforms:

  • epoll: Linux, Android, RedoxOS
  • kqueue: macOS, iOS, tvOS, watchOS, FreeBSD, NetBSD, OpenBSD, DragonFly BSD
  • event ports: illumos, Solaris
  • poll: VxWorks, Fuchsia, HermitOS, 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.