Closed sjames closed 3 years ago
What about use from_raw_fd
like this:
let listener = std::os::unix::net::UnixListener::bind("/tmp/1").unwrap(); // already established connection
let mut server;
unsafe {
server = Server::from_raw_fd(listener.as_raw_fd()).set_domain_unix()
}
server.start().await.unwrap();
I noticed that start_single
function in your code, but I don't understand in what situations can this be used, I think the ttrpc server should serve for all connections.
Normally yes, the server should serve connections. But I have a special need to have a point-to-point RPC mechanism. The sockets are created outside and passed into the server and client. This works fine on the client, but since the server binds to the socket waiting for connections, I cannot pass in a pre-connected descriptor.
I call the start_single function, giving it a pre-connected UnixStream that is created using UnixStream::pair(). One end of the pair is made available to the child process on clone, and the child creates the ttrpc Client.
It sounds reasonable. What about extract a stream handle method from the do_start
method?
Yes that should work too. As long as we can avoid binding to the socket, any option is fine. :-)
Can you create a PR for it?
Yup, will do that. I need to think about this a bit.
Thanks for the nice project by the way! I've been on the hunt for a lightweight RPC for rust for quite some time.
Cheers, Sojan
Is your feature request related to a problem? Please describe.
I want to run a server on a pre-connected socket. The current implementation attempts to listen to the file-descriptor.
Describe the solution you'd like It will be good to have a routine to run the server on a socket with an already established connection to a client socket. I tried an experiment and and this seems to work. Would you consider this feature enhancement?
Changes to my forked version: https://github.com/sjames/ttrpc-rust/commit/018b5a23a3dac73448fe117f07fb228fe7839da0 https://github.com/sjames/ttrpc-rust/commit/e9c0d0aa967f3938a8b9e7112ff2f8f1ce1a31be
Describe alternatives you've considered None.