smol-rs / polling

Portable interface to epoll, kqueue, event ports, and wepoll
Apache License 2.0
551 stars 68 forks source link

`Polling::new` failing on espidf (esp32c3) with `PermissionDenied` error #183

Closed ids1024 closed 9 months ago

ids1024 commented 9 months ago

I'm not sure if something was different when this was added to polling, but trying with a simple project based on https://github.com/esp-rs/esp-idf-template on nightly Rust, the call to eventfd fails.

Looking at https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/storage/vfs.html#eventfd, it seems some additional code is needed to support eventfd. Which I see works with something like this:

unsafe {
    esp_idf_svc::sys::esp_vfs_eventfd_register(&esp_idf_svc::sys::esp_vfs_eventfd_config_t {
        max_fds: 1,
    })
};

Not sure what polling can do here. Other than documentation? Or maybe produce a more useful error.

notgull commented 9 months ago

The error returned by polling could be a lot more informative as to the cause of this error.

notgull commented 9 months ago

cc @ivmarkov

ivmarkov commented 9 months ago

I guess the root cause is this call failing.

Any suggestions what to do there (I'm not very good at dealing with std::io::Error).

Not sure if possible to decorate it at all with a human readable message (something like "Did you initialize the VFS subsystem of ESP IDF and do you have enough event handles"?).

ids1024 commented 9 months ago

io::Error is a kind of weird API, but it's flexible enough. It would be sufficient to catch the PermissionDenied then call io::Error::new with the same ErrorKind (or a different one) and a string with a specific message. Or define a new error type to pass to io::Error::new here.

ivmarkov commented 9 months ago

Maybe you can contribute a PR with that? :) (I'm completely underwater trying to fix, "example"-ify and release the new version of the esp-idf-* crates, so any help would be greatly appreciated.)

Btw, this is coming in the new release, so you don't need to call into the unsafe esp-idf-sys APIs for the eventfd VFS initialization anymore.