Skip to content
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 UDS support for Unix systems #1098

Merged
merged 36 commits into from
Oct 9, 2019
Merged

Conversation

kleimkuhler
Copy link
Contributor

Summary

This change adds UDS support for Unix systems. The networking primitives
src/net/uds. These modules provide the structs for UnixDatagrams,
UnixListeners, and UnixStreams. Each of the methods on these structs
dispatch to the Unix system structs in src/sys/unix/uds.rs.

Use of these new structs should feel fairly similar to the Tcp[...]
equivalents. The tests added also reflect the similar behavior that would be
expected.

Details

Since this change only adds UDS support, there should be no behavior changes
anywhere else. For reviewing, I recommend starting from the networking
primitives and seeing what methods they dispatch to.

The tests added in tests/uds.rs should feel fairly similar to
tcp_stream.rs--the main difference coming from supporting PathBufs as the
socket address to connect to.

I originally pulled in some testing infrastructure added to v0.6.x in #944,
but ultimately found the functionality to not be as helpful due to a lot of
changes that have since taken place in master. I think #944 could still be
helpful, but as a separate change that is more about improving testing
functionality and not included in a change that introduces additional
functionality.

Signed-off-by: Kevin Leimkuhler kleimkuhler@icloud.com

carllerche and others added 20 commits September 27, 2019 14:13
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
@asomers
Copy link
Collaborator

asomers commented Oct 1, 2019

How does this PR compare to alexchrichton/mio-uds ?

src/net/uds/datagram.rs Outdated Show resolved Hide resolved
src/sys/unix/uds.rs Outdated Show resolved Hide resolved
src/sys/unix/uds.rs Outdated Show resolved Hide resolved
src/sys/unix/uds.rs Outdated Show resolved Hide resolved
src/sys/unix/uds.rs Outdated Show resolved Hide resolved
src/sys/unix/uds.rs Outdated Show resolved Hide resolved
src/sys/unix/uds.rs Outdated Show resolved Hide resolved
src/sys/unix/uds.rs Outdated Show resolved Hide resolved
src/net/uds/listener.rs Outdated Show resolved Hide resolved
@carllerche
Copy link
Member

@asomers this is updating the UDS implementation to the latest mio. It also moves it in tree because std now supports UDS and moving it in tree reduces the number of dependencies.

Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Copy link
Collaborator

@Thomasdezeeuw Thomasdezeeuw left a comment

Choose a reason for hiding this comment

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

Overall this looks good, I've add a couple of comments but there are mostly small nits.

I haven't had time to look at the tests yet.

src/net/uds/datagram.rs Outdated Show resolved Hide resolved
src/net/uds/datagram.rs Outdated Show resolved Hide resolved
src/net/uds/datagram.rs Outdated Show resolved Hide resolved
src/net/uds/datagram.rs Outdated Show resolved Hide resolved
src/net/uds/datagram.rs Outdated Show resolved Hide resolved
src/sys/unix/uds.rs Outdated Show resolved Hide resolved
src/net/uds/stream.rs Outdated Show resolved Hide resolved
src/net/uds/listener.rs Outdated Show resolved Hide resolved
src/net/uds/stream.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
This introduced problems cross-platform

Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
@kleimkuhler
Copy link
Contributor Author

Same as for UnixDatagram and UnixListener:

  • std -> sys,
  • std::os::unix::net::UnixListener -> net::UnixListener, and
  • add SelectorId.

@Thomasdezeeuw I'm not sure I follow all the parts of this comment in UnixStream, UnixDatagram, and UnixListener.

I can rename the std field to sys, and I have added the selector_id field for debug assertions.

I'm not sure I follow std::os::unix::net::UnixListener -> net::UnixListener. These types are not available in std::net, they are only available through these paths and must be imported directly.

This commit introduces a significant restructure from the original UDS
support proposal. Originally, the UDS types dispatched the the `std` UDS
types from the `net` module. This was different from other `net` module
types because it did not use the `sys` modules types for that OS.

This was okay because currently UDS is only supported by Unix, but when
windows support is added this would have been a problem.

The new structure sets up most of the work for Windows UDS support as
the `net` module UDS types now all dispatch to their inner `sys` module
types.

Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
@kleimkuhler
Copy link
Contributor Author

@Thomasdezeeuw I think most of your comments should be addressed from the last commit. Below is my commit message:

This commit introduces a significant restructure from the original UDS
support proposal. Originally, the UDS types dispatched the the std UDS
types from the net module. This was different from other net module
types because it did not use the sys modules types for that OS.

This was okay because currently UDS is only supported by Unix, but when
windows support is added this would have been a problem.

The new structure sets up most of the work for Windows UDS support as
the net module UDS types now all dispatch to their inner sys module
types.

I have left all your comments from your last review that had to do with this unresolved, but I think they should all be addressed at this point.

src/sys/unix/uds/mod.rs Outdated Show resolved Hide resolved
src/net/uds/datagram.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@Thomasdezeeuw Thomasdezeeuw left a comment

Choose a reason for hiding this comment

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

This looks good to me, thanks @kleimkuhler.

tests/uds.rs Outdated Show resolved Hide resolved
tests/uds.rs Show resolved Hide resolved
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
This did not work across all plaforms :(

This reverts commit 9d9cbc6.
@Thomasdezeeuw
Copy link
Collaborator

Since this change is so large, can some double check this and merge if acceptable?

///
/// [`net::SocketAddr`]: std::os::unix::net::SocketAddr
/// [`accept`]: #method.accept
pub struct SocketAddr {
Copy link
Member

Choose a reason for hiding this comment

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

Let's not do it in this PR, but as a follow up it would be nice to move this type to a separate file.

use std::io;
use std::net::Shutdown;
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
use std::os::unix::net::SocketAddr;
Copy link
Member

Choose a reason for hiding this comment

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

It looks like we are using the std version of SocketAddr here. Should we focus on only using mios version?

}

/// Returns the local socket address of this listener.
pub fn local_addr(&self) -> io::Result<net::SocketAddr> {
Copy link
Member

Choose a reason for hiding this comment

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

Same: should we focus on only using mio's version of SocketAddr?

use std::io::{self, IoSlice, IoSliceMut};
use std::net::Shutdown;
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
use std::os::unix::net::SocketAddr;
Copy link
Member

Choose a reason for hiding this comment

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

Same: should we focus on only using mio's version of SocketAddr?

Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

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

Looks great to me. One thought, which I added inline, should we only use mio's definition of SocketAddr (for consistency)? Again, if/when std allows external construction of SocketAddr, we can switch all at once.

@kleimkuhler
Copy link
Contributor Author

@carllerche I had limited the use of mio's SocketAddr because it had felt more like an inconvenience that libstd's SocketAddr was not public; I leaned towards using it in the least amount of places possible.

That's a good point though about using it everywhere for now and changing over all at once when we can. I'll make that change!

Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
@kleimkuhler
Copy link
Contributor Author

@carllerche Had to introduce some further mio::unix::SocketAddr functionality to return it everywhere it is used, but net::SocketAddr is no longer used now.

Also fixed a cfg in the UDS tests that was not actually running them correctly.

Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

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

Thanks for the work and taking this to completion 👍

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.

None yet

5 participants