That's a nice problem. As far as I know, the Rust standard library doesn't have a way to create a TcpStream that wraps an existing raw file descriptor. You can only get a raw file descriptor via FFI anyway, so that's fine for most programs.
that's a good idea, but keep in mind that the underlying file descriptor could be of a UDP stream, or a TCP stream to another host. I finally solved the problem, check out https://github.com/dzervas/mage/blob/master/src/api_ffi.rs. When you bind or connect, I return a "file descriptor" that you will pass back to me and I use it as an index to a vector of connections :)
It works fairly good - although I have other problems...
True enough! I thought you were just going to see existing connections or something. What you're doing is probably what's going on under the hood anyway.
3 comments
[ 2.1 ms ] story [ 13.7 ms ] threadA TcpStream is just a struct containing the file descriptor (https://github.com/rust-lang/rust/blob/master/src/libstd/sys...) and nothing else, so this would be fine:
It works fairly good - although I have other problems...