#linux #epoll #filesystem

epoll-rs

High level bindings to linux's epoll interface

3 releases

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

#320 in Unix APIs

Download history 20/week @ 2023-10-28 15/week @ 2023-11-04 15/week @ 2023-11-11 19/week @ 2023-11-18 20/week @ 2023-11-25 20/week @ 2023-12-02 9/week @ 2023-12-09 16/week @ 2023-12-16 19/week @ 2023-12-23 9/week @ 2023-12-30 11/week @ 2024-01-06 13/week @ 2024-01-13 14/week @ 2024-01-20 18/week @ 2024-01-27 9/week @ 2024-02-03 25/week @ 2024-02-10

68 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

~130KB