3 releases

0.2.2 Aug 10, 2023
0.2.1 Aug 13, 2021
0.2.0 Aug 11, 2021

#972 in Unix APIs

Download history 4/week @ 2024-07-27 1/week @ 2024-08-24 3/week @ 2024-08-31 18/week @ 2024-09-21 1/week @ 2024-09-28 1/week @ 2024-10-05

61 downloads per month
Used in miku-rpc

MIT/Apache

29KB
455 lines

Epoll-rs

What is it?

Epoll-rs is a difficult to misuse, high-level binding to Linux's epoll interface. It provides the Epoll type, which wraps an epoll file descriptor, just like std::fs::File wraps normal file descriptors.

Why

epoll is too low level. It is a safe wrapper around epoll, so doesn't require the use of unsafe, but has sharp edges, like needing to use epoll::close instead of automatically calling close on drop and making the API consumer deal exclusively with RawFds and not Files.

Mio is complicated because it aims to support multiple platforms, which epoll-rs doesn't.

How do I use it?

See the examples directory and top level api documentation


lib.rs:

A rusty wrapper for Linux's epoll interface that is easy to use and hard to misuse.

Create a new epoll instance with Epoll::new. Add any struct that implements the OwnedRawFd trait with Epoll::add. epoll::add returns a Token that takes ownership of the added file.

use epoll_rs::{Epoll, Opts};
let mut epoll = Epoll::new()?;
let token = epoll.add(file, Opts::IN)?;

Tokens returned from one epoll instance cannot be used with another instance. Doing so will cause a panic in debug mode and undefined behavior in release mode.

use epoll_rs::{Epoll, Opts};
let mut epoll1 = Epoll::new()?;
let mut epoll2 = Epoll::new()?;
let token1 = epoll1.add(file, Opts::IN)?;
let res = epoll2.remove(token1); // <- undefined behavior in release mode

Dependencies

~150KB