Skip to content

Commit

Permalink
Annotate ESP-IDF EPERM error with eventfd info
Browse files Browse the repository at this point in the history
If eventfd isn't initialized, `Polling::new` will fail with an EPERM
error. You need to call the "esp_vfs_eventfd_register" function to
initialize the eventfd subsystem in ESP-IDF. This commit indicates to
the user that this needs to happen.

Signed-off-by: John Nunley <[email protected]>
  • Loading branch information
notgull committed Jan 28, 2024
1 parent ae484a0 commit 62430fd
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,13 +571,20 @@ mod notify {
// (1) is not a problem for us, as we want the eventfd() file descriptor to be in a non-blocking mode anyway
// (2) is also not a problem, as long as we don't try to read the counter value in an endless loop when we detect being notified

#[cfg(not(target_os = "espidf"))]
let flags = EventfdFlags::NONBLOCK;

#[cfg(target_os = "espidf")]
let flags = EventfdFlags::empty();

let event_fd = eventfd(0, flags)?;
let event_fd = eventfd(0, flags).map_err(|err| {
match err {
rustix::io::Errno::PERM => {
// EPERM can happen if the eventfd isn't initialized yet.
// Tell the user to call esp_vfs_eventfd_register.
io::Error::new(
io::ErrorKind::PermissionDenied,
"failed to initialize eventfd for polling, try calling `esp_vfs_eventfd_register`"
)
},
err => io::Error::from(err),
}
})?;

Ok(Self { event_fd })
}
Expand Down

0 comments on commit 62430fd

Please sign in to comment.