3 ms·
I don't see why that would require making all code unsafe? You might want to take a look at mio's source code [1], which uses epoll on Linux [2], and which enca
by adwn 4y ago
I don't see why that would require making all code unsafe? You might want to take a look at mio's source code [1], which uses epoll on Linux [2], and which encapsulates epoll in a safe way.
[1] https://github.com/tokio-rs/mio https://github.com/tokio-rs/mio
[2] https://tokio-rs.github.io/mio/doc/mio/struct.Poll.html#implementation-notes https://tokio-rs.github.io/mio/doc/mio/struct.Poll.html#impl...
- lelanthran 4y agoAfter looking at the examples, it looks to me that it uses a hashmap (with a generated token to identify the connection structure). It gets around putting a ptr into the event structure (that epoll will then return) by putting a tokenID into it instead (that epoll returns), that the connection_handler function will then use to retrieve the connection instance that it needs to work with. IOW, in `C` I'd create an instance of a `struct connection_t` and `epoll_wait()` returns the pointer to the instance. This way, it appears that an ID is placed into the event structure and the { ID : corresponding instance } tuple is stored in a hashmap. `epoll_wait()` returns the ID, the caller uses that ID to get an instance to work with. Although, I could be wrong - I'm not a Rust dev.