-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "borrowed-fd" feature for sending BorrowedFd on a socket #15
base: master
Are you sure you want to change the base?
Conversation
This is a more ergonomic way to use slices of ownership-safe file descriptors instead of coercing them into raw objects.
@Ekleog @lovesegfault I distinctly remember us considering something like this back when we were developing this crate and finding reasons to go with |
Ah, never mind, these are io-safety types rather than conversion traits. Ignore my Q. |
seems good to me implementation wise though I can't say I love the duplication. My intuition is that we could make all our apis follow the i/o safety paradigm and just drop the Unfortunately we cannot use |
Can we have an Then we could take |
Couldn't this just be an |
Issue with either of these trait suggestions is that you cannot construct a |
You can never construct In any case the allocation argument is moot since you're writing directly into an allocated cmsghdr, there is no opportunity to reuse the input slice. |
I wouldn't be surprised if this was the reason we originally went with I was thinking back to my message on whether we would be better off with replacing The current duplication until we find another good reason to make a breaking change might not be too terrible either, but you will need to adjust the CI before this can land regardless. |
Actually thinking about it some more, there is one way to do that: pub trait AsFdSlice {
fn write_fd_slice<'a>(&'a self, buf: &'a mut Vec<RawFd>) -> &'a [RawFd];
}
impl AsFdSlice for &[RawFd] {
fn write_fd_slice<'a>(&'a self, _: &'a mut Vec<RawFd>) -> &'a [RawFd] {
self
}
}
impl<A: AsRawFd, B: AsRawFd> AsFdSlice for (A, B) {
fn write_fd_slice<'a>(&'a self, buf: &'a mut Vec<RawFd>) -> &'a [RawFd] {
buf.clear();
buf.reserve_exact(2);
buf.push(self.0.as_raw_fd());
buf.push(self.1.as_raw_fd());
&buf
}
}
// etc., implemented by a macro for tuples up to 16 objects Then we could take WDYT? |
Shrug. I know I kinda started the discussion here, but it feels like a waste of brainpower to give this crate too much design work and making it do something super fancy given that there's an unstable libstd equivalent. Once that one is done baking this crate will have served its purpose. Any braincells going into making sending of file descriptors around simple, convenient, fast, zero-cost, sound or anything else are perhaps better spent there. But if we must do something fancy, then this crate could at least serve as a testing ground for the libstd APIs. For instance they appear to have trouble with OS support matrix, which I think we never too much trouble with. Not that I expect any of us to have the necessary bandwidth or motivation for such work (especially given the presence of somebody else already working on pushing this through on the libstd side.) |
I think my progress is going to be limited here: 1 - regarding fanciness/deduplication, I don't have enough context here to understand the goals behind the intermediate buffer or OS support matrix; but a Though libstd progress aside, feels like there's at least another 18 months' usage out of this crate especially if targeting older rust. |
This is a more ergonomic way to use slices of ownership-safe file descriptors instead of coercing them into raw objects.