mirror of https://github.com/smol-rs/polling
e85331c437
Dragonfly BSD 6.4.0 VM doesn't seem to have git. ``` error: failed to get `cfg-if` as a dependency of package `polling v2.5.2 (/Users/runner/work/polling/polling)` Caused by: failed to load source for dependency `cfg-if` Caused by: Unable to update registry `crates-io` Caused by: failed to fetch `https://github.com/rust-lang/crates.io-index` Caused by: could not execute process `git fetch --force --update-head-ok 'https://github.com/rust-lang/crates.io-index' '+HEAD:refs/remotes/origin/HEAD'` (never executed) Caused by: No such file or directory (os error 2) ``` |
||
---|---|---|
.github | ||
examples | ||
src | ||
tests | ||
.cirrus.yml | ||
.gitignore | ||
CHANGELOG.md | ||
Cargo.toml | ||
LICENSE-APACHE | ||
LICENSE-MIT | ||
README.md | ||
build.rs |
README.md
polling
Portable interface to epoll, kqueue, event ports, and wepoll.
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
- wepoll: 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
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
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.