-
Notifications
You must be signed in to change notification settings - Fork 6
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 a socketstream_seqpacket
feature.
#3
Conversation
Add a `socketstream_seqpacket` feature, which uses `SOCK_SEQPACKET` on Unix-type platforms and `PIPE_TYPE_MESSAGE` on Windows.
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.
Wow, that was fast! 🚀
OK I'll try this out soon.
src/rustix.rs
Outdated
/// Create a socketpair and return seqpacket handles connected to each end. | ||
#[inline] | ||
pub fn socketpair_seqpacket() -> io::Result<(SocketpairStream, SocketpairStream)> { | ||
Ok(rustix::net::socketpair( |
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.
I haven't seen this style before of "early Ok wrapping then map()
". What's the advantage over something like the following which I feel like I've seen much more commonly in other Rust code?
diff --git a/src/unix.rs b/src/unix.rs
index 9f8c876..ea58b29 100644
--- a/src/unix.rs
+++ b/src/unix.rs
@@ -55,22 +55,18 @@ pub fn socketpair_stream() -> io::Result<(SocketpairStream, SocketpairStream)> {
/// Create a socketpair and return seqpacket handles connected to each end.
#[inline]
pub fn socketpair_seqpacket() -> io::Result<(SocketpairStream, SocketpairStream)> {
- Ok(rustix::net::socketpair(
+ let (a, b) = rustix::net::socketpair(
AddressFamily::UNIX,
SocketType::SEQPACKET,
SocketFlags::CLOEXEC,
Protocol::default(),
- )
- .map(|(a, b)| {
- let a = a.into_raw_fd();
- let b = b.into_raw_fd();
- unsafe {
- (
- SocketpairStream::from_raw_fd(a),
- SocketpairStream::from_raw_fd(b),
- )
- }
- })?)
+ )?;
+ unsafe {
+ Ok((
+ SocketpairStream::from_raw_fd(a.into_raw_fd()),
+ SocketpairStream::from_raw_fd(b.into_raw_fd()),
+ ))
+ }
}
impl Read for SocketpairStream {
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.
No particular advantage; it just fell out from how the code evolved one step at a time. I've changed it to your suggestion now, which I agree is easier to read :-).
(My goal here is to drop the Here's what I have so far that compiles:
Two questions:
|
For eliminating that
Though if you need Windows support, that's more complex, as Windows doesn't support any form of |
👍
No need for Windows for me.
Yeah, that's what I was suspecting. Makes this more of a mixed bag for me since I'd be using That said...while this is obviously up to you, I'd still say this is worth merging. I might try to do a push to do |
Yeah, though I expect we will eventually implement
Very cool! I'd be interested to hear how it goes :-). |
Add a
socketstream_seqpacket
feature, which usesSOCK_SEQPACKET
onUnix-type platforms and
PIPE_TYPE_MESSAGE
on Windows.