Running code on the RawFd before connecting a TcpStream?


#1

I’m experimenting with Android VpnService.
Any outgoing socket connection needs to be protected by calling a Java method with the socket fd passed in before connecting, but our TcpStream immediately connects to the server.
Is there any way to achieve this?


#2

net2’s TcpBuilder can probably help: https://doc.rust-lang.org/net2-rs/net2/struct.TcpBuilder.html


#3

Is there anything similar in Tokio?


#4

You can create a tokio tcpstream from a std::net one: https://tokio-rs.github.io/tokio-core/tokio_core/net/struct.TcpStream.html#method.connect_stream.