Comments (4)
I guess that mio has to use platform-dependent integers because the value of the token is stored in the internal data of epoll/kqueue, so there is no way to use a generic value, bigger than 32/64 bits.
Maybe, you can use a (really ugly) hack using a box and std::mem::transmute
.
let my_data = box MyData::new(...);
let my_data_token: uint = unsafe { mem::transmute(my_data) };
from mio.
- Before mentioned patch mio was using trait Token that allowed converting to uint, so no problem here.
- Also, uint may or may not what you think it is. IIRC it's defined in Rust as minimum number enough to hold a pointer, which is not how it is defined in C/C++ - see e.g. discussion in https://github.com/1fish2/Rust-rfcs/blob/int-index-for-portability/active/0000-intindex.md
from mio.
The reason that I moved away from the generic for socket tokens was because
a) Like @ayosec mentioned, it is stored by epoll / kqueue and must be no bigger than a pointer size. As of now in the rust reference manual, uint is defined as the equivalent to C's uintptr_t, which is what is needed. If rust decides to change the meaning of uint, then Token will need to be updated to explicitly mean pointer sized.
b) There is no way to run drop functions correctly and any trait for the socket token would have to implement Copy.
Given these two requirements (and the inability to set size bounds on traits), it didn't seem worth making the socket token generic. I expect the main usage pattern will be to store of state in some structure and then pass the token to mio. As to why Token vs. just going w/ a raw number? I prefer making types specific to the use case at hand, but that might be personal preference.
Now, regarding why I didn't use Token across the board, the limitation is quite annoying, and I didn't see a reason to arbitrarily limit the the API. I completely disagree that it is of little use. I am finding it quite useful. Avoiding the double lookup when possible has benefits.
from mio.
There is no way to run drop functions correctly and any trait for the socket token would have to implement Copy.
Just to clarify, I believe what @carllerche is saying is that even though epoll
removes closed FDs from the set, we have not found a reliable way to learn when an FD has been closed. This means that we have no way to drop
tokens when the associated FD is no longer active, which will cause bad memory leaks.
from mio.
Related Issues (20)
- Setup WASM/WASI CI
- get any errors when i use `wasm-pack` command by `mio` HOT 4
- Need switch to not use eventfd on `target_os = "linux"` HOT 4
- Add ESP-IDF framework support
- IoRing support for windows HOT 1
- Has waker check doesn't work with try_cloned Registries HOT 1
- compile time error inside `poll.rs` HOT 3
- poll: Optimize locks and allocations in the critical path
- Poll(2) implementation follow-ups
- Official ESP-IDF framework support HOT 3
- Make `CompletionPort` public? HOT 7
- No data coming from Poll HOT 8
- Difference behaves between Linux and Windows HOT 2
- How to wait for a socket to be writable? udp / Interest::READABLE | Interest::WRITABLE HOT 6
- could not compile mio due to 44 previous errors HOT 3
- WakerRegistrar mentioned in comment is not present HOT 2
- Decide MSRV for v1 HOT 2
- Use rustix instead of libc HOT 2
- Document MSRV policy HOT 1
- Update socket types API to match std lib HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mio.