Git Product home page Git Product logo

Comments (4)

ayosec avatar ayosec commented on May 21, 2024

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.

dtantsur avatar dtantsur commented on May 21, 2024
  1. Before mentioned patch mio was using trait Token that allowed converting to uint, so no problem here.
  2. 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.

carllerche avatar carllerche commented on May 21, 2024

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.

wycats avatar wycats commented on May 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.