Skip to content

Implement Unix domain sockets in libnative #11484

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

Closed
wants to merge 1 commit into from

Conversation

Geal
Copy link
Contributor

@Geal Geal commented Jan 11, 2014

Fix #11201
No Windows named pipes for now and the libuv implementation is missing too
There is a special case for datagram sockets like /dev/log

@@ -159,6 +159,8 @@ pub trait IoFactory {
fn unix_bind(&mut self, path: &CString) ->
Result<~RtioUnixListener, IoError>;
fn unix_connect(&mut self, path: &CString) -> Result<~RtioPipe, IoError>;
fn unix_dgram_connect(&mut self, path: &CString) -> Result<~RtioDatagramPipe, IoError>;
fn unix_dgram_bind(&mut self, path: &CString) -> Result<~RtioDatagramPipe, IoError>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wary to add these new primitives when we don't have a clear timeline to adding this support to librustuv. Do you have any idea if libuv is intending on supporting this soon? If so, then I think this is ok to put in, but if not, I don't want to let the I/O implementations fall too far out of sync. Right now libnative is playing catch-up, and I don't want to play a perpetual game of "libX needs to catch up to libY".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reference I have seen is this: Dropping support for unix datagram sockets
There are two ways here: either we add a parameter to connect and bind to support the socket type (but uv would not support datagram), or those two methods could be exported from native::io::net, but that would fragment more the API.
I could try to add the feature in librustuv (it was my first intention because unix sockets already work there), but I had a hard time getting around the code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! Let's back out this addition from this patch, open an issue with your code, and have discussion continue there. If libuv intentionally removed this functionality, then we'll need to think carefully if we want to add it back.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, the patch can wait a bit until this is sorted out. I will need it anyway because I want to send messages to syslog, but that leaves me some time to write the syslog library itself :)

@alexcrichton
Copy link
Member

Do you know how well this patch works on windows? I would imagine that some errors should be raised somewhere, but I'm curious if it compiles and where it dies.

@Geal
Copy link
Contributor Author

Geal commented Jan 12, 2014

I have not tested it on Windows yet. I'll check on Monday when I get another laptop. Is it possible to cross compile for Win32? I compile on a quad core server, and the build still takes a long time, so it will be even longer on my laptop.

@Geal
Copy link
Contributor Author

Geal commented Jan 12, 2014

After verification: the socket() function on Windows does not have AF_UNIX, so it would probably compile, but return an error on the libc::socket call.

It should be implemented with named pipes. I could take care of that too, but I would need some guidance on how to interact with the WIn32 API from Rust.

@Matthias247
Copy link
Contributor

I wouldn't try to provide a common API for Unix domain sockets and Windows named pipes. They are conceptually quite different. Unix domain sockets are point to point and bidirectional. You can have server sockets that can accept new point-to-point connections. Named pipes can be point-to-point as well as multipoint-to-point, unidirectional and bidirectional and there is no such thing as dedicated server socket.

I would better say that Unix domain sockets are simply not supported in Windows and provide a special named pipe API for Windows. However I don't know if it's worth it, as they are not used that much.

@alexcrichton
Copy link
Member

re windows, that behavior sounds fine to me. When this gets merged I'll update the ticket to indicate that windows support is all that remains.

We're currently bringing the native I/O implementation up to par with the libuv-backed I/O implementation. For now I think it's a good idea to mirror libuv's api (at least in the stdlib for now). If the two use cases are fundamentally different, then I would like to explore other routes in order to have platform-specific I/O exposed from the standard library. For now, sticking to the existing traits should be "good enough"

@Geal
Copy link
Contributor Author

Geal commented Jan 15, 2014

Oops, I don't know what happened there. I'll cherry pick and squash my commits in the final pull request.

In the mean time:
some docs were converted to doc blocks, I remove the unix_dgram_* functions (but the feature is still available by direct import of native::io), the sun_path length is now a static variable in libc, and I fixed the code to work on OSX.

@alexcrichton
Copy link
Member

The diff views have gotten a little conflated from this now, could you rebase away all the already-merged commits?

@Geal
Copy link
Contributor Author

Geal commented Jan 16, 2014

Alright, I squashed the commit, it should be easier to read now. I updated the code examples to match the API.

cast::transmute(storage)
};
unsafe {
let buf:[libc::c_char, ..libc::sun_len] = storage.sun_path;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to copy sun_path into a local, you can call as_ptr on it directly.

@alexcrichton
Copy link
Member

Closing due to inactivity, but feel free to reopen with a rebase!

@Geal
Copy link
Contributor Author

Geal commented Jan 28, 2014

I got stucked on over stuff in the meantime. I'm fixing the code, rebasing, and I'll push another patch before the end of the week.

@alexcrichton
Copy link
Member

No problem, and thanks!

@brson
Copy link
Contributor

brson commented Feb 3, 2014

Would love to see this get through. One of the last big steps before turning on libnative by default.

flip1995 pushed a commit to flip1995/rust that referenced this pull request Sep 25, 2023
[`extra_unused_type_parameters`]: Fix edge case FP for parameters in where bounds

Generic parameters can end up being used on the left side of where-bounds if they are not directly bound but instead appear nested in some concrete generic type. Therefore, we should walk the left side of where bounds, but only if the bounded type is *not* a generic param, in which case we still need to ignore the bound.

Fixes rust-lang#11302

changelog: [`extra_unused_type_parameters`]: Fix edge case false positive for parameters in where bounds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unix pipes (named pipes on windows) need a 1:1 implementation
4 participants