-
Notifications
You must be signed in to change notification settings - Fork 41
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
Some changes to RawFdContainer
#386
Conversation
Hmm, this is causing issues on windows + libxcb |
Basically 👍 for the PR. Ultimately, it feels to me like that raw fd stuff is something that is not well supported by Rust. That seems like the source of some of the problems we experience. The old code was generic enough to "support anything". No idea how to easily preserve that. Or, as Travis puts it:
Implementing conversion for "everything" by hand cannot really work. It would only ever cover stuff that is in std and would break for any new additions to std.
That does not seem too bad and can easily be fixed with some feature checks in
I think originally I wanted to have the |
You could add an explicit panic when |
In that case,
I was thinking adding something like a I don't have much time now, so I will continue to work on this later. |
Hm. Such a change would carry through to all of the generated code (well, at least for those extension that have FD passing stuff). And it would make the return type of Also, I still want to make How about using the |
068e3d3
to
a8a057b
Compare
src/utils.rs
Outdated
/// | ||
/// The `RawFdContainer` takes ownership of the `RawFd` and closes it on drop. | ||
/// | ||
/// This function panics on non-unix systems. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update/fix the docs? (I guess just removing the last sentence is the enough)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/utils.rs
Outdated
/// with `dup`. The new `RawFdContainer` will take ownership | ||
/// of the `dup`ed version, whereas the original `RawFdContainer` | ||
/// will keep the ownership of is FD. | ||
pub fn try_clone(&self) -> nix::Result<Self> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes nix
appear in the public API. I think I would like to avoid that.
I would propose something like this instead:
x11rb/src/rust_connection/stream.rs
Lines 154 to 155 in f792a01
// Nothing touched errno since sendmsg() failed | |
let res = res.map_err(|_| std::io::Error::last_os_error())?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/utils.rs
Outdated
/// Tries to clone the `RawFdContainer` creating a new FD | ||
/// with `dup`. The new `RawFdContainer` will take ownership | ||
/// of the `dup`ed version, whereas the original `RawFdContainer` | ||
/// will keep the ownership of is FD. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// will keep the ownership of is FD. | |
/// will keep the ownership of its FD. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/utils.rs
Outdated
/// | ||
/// This is similar to dropping the `RawFdContainer`, but it allows | ||
/// the caller to handle errors. | ||
pub fn close(self) -> nix::Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above about nix::Result
appearing in the public API
src/utils.rs
Outdated
/// A simple wrapper around RawFd that closes the fd on drop. | ||
/// | ||
/// On non-unix systems, or when the `allow-unsafe-code` is disabled, | ||
/// this type is empty and does not provide any method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please copy the doc from the unix
version of RawFdContainer
(this still talks about allow-unsafe-code
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/xcb_ffi/mod.rs
Outdated
#[cfg(not(unix))] | ||
{ | ||
// It is not possible to create a `RawFdContainer` on non-unix. | ||
unreachable!(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move the comment (or something like it) into the argument of unreachable!
? (I think unreachable!("foo")
should work, does it?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
* Methods are not provided at all on non-unix systems or when `allow-unsafe-code` is disabled. Trying to create a `RawFdContainer` when it is not available will cause a compile error instead of panicking at runtime. * `drop` does not panic on failure. Instead, a `close` method is provided that allows the caller to check for errors. * A `try_clone` method has been added. It allows to clone a `RawFdContainer` creating a new FD with `dup`.
a8a057b
to
9413ba1
Compare
allow-unsafe-code
is disabled. Trying to create aRawFdContainer
when it is not available will cause a compile error instead of panicking at runtime.drop
does not panic on failure. Instead, aclose
method is provided that allows the caller to check for errors.try_clone
method has been added. It allows to clone aRawFdContainer
creating a new FD withdup
.