-
Notifications
You must be signed in to change notification settings - Fork 744
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
Adds support for UnixStream and UnixListener on Windows #1667
Closed
KolbyML
wants to merge
3
commits into
tokio-rs:master
from
KolbyML:continue-the-work-of-UnixStream-for-windows
+1,247
−175
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use crate::sys; | ||
use std::path::Path; | ||
use std::{ascii, fmt}; | ||
|
||
/// An address associated with a `mio` specific Unix socket. | ||
/// | ||
/// This is implemented instead of imported from [`net::SocketAddr`] because | ||
/// there is no way to create a [`net::SocketAddr`]. One must be returned by | ||
/// [`accept`], so this is returned instead. | ||
/// | ||
/// [`net::SocketAddr`]: std::os::unix::net::SocketAddr | ||
/// [`accept`]: #method.accept | ||
pub struct SocketAddr { | ||
inner: sys::SocketAddr, | ||
} | ||
|
||
struct AsciiEscaped<'a>(&'a [u8]); | ||
|
||
pub(crate) enum AddressKind<'a> { | ||
Unnamed, | ||
Pathname(&'a Path), | ||
Abstract(&'a [u8]), | ||
} | ||
|
||
impl SocketAddr { | ||
pub(crate) fn new(inner: sys::SocketAddr) -> Self { | ||
SocketAddr { inner } | ||
} | ||
|
||
fn address(&self) -> AddressKind<'_> { | ||
self.inner.address() | ||
} | ||
} | ||
|
||
cfg_os_poll! { | ||
impl SocketAddr { | ||
/// Returns `true` if the address is unnamed. | ||
/// | ||
/// Documentation reflected in [`SocketAddr`] | ||
/// | ||
/// [`SocketAddr`]: std::os::unix::net::SocketAddr | ||
pub fn is_unnamed(&self) -> bool { | ||
matches!(self.address(), AddressKind::Unnamed) | ||
} | ||
|
||
/// Returns the contents of this address if it is a `pathname` address. | ||
/// | ||
/// Documentation reflected in [`SocketAddr`] | ||
/// | ||
/// [`SocketAddr`]: std::os::unix::net::SocketAddr | ||
pub fn as_pathname(&self) -> Option<&Path> { | ||
if let AddressKind::Pathname(path) = self.address() { | ||
Some(path) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
/// Returns the contents of this address if it is an abstract namespace | ||
/// without the leading null byte. | ||
// Link to std::os::unix::net::SocketAddr pending | ||
// https://github.com/rust-lang/rust/issues/85410. | ||
pub fn as_abstract_namespace(&self) -> Option<&[u8]> { | ||
if let AddressKind::Abstract(path) = self.address() { | ||
Some(path) | ||
} else { | ||
None | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Debug for SocketAddr { | ||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(fmt, "{:?}", self.address()) | ||
} | ||
} | ||
|
||
impl fmt::Debug for AddressKind<'_> { | ||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
AddressKind::Unnamed => write!(fmt, "(unnamed)"), | ||
AddressKind::Abstract(name) => write!(fmt, "{} (abstract)", AsciiEscaped(name)), | ||
AddressKind::Pathname(path) => write!(fmt, "{:?} (pathname)", path), | ||
} | ||
} | ||
} | ||
|
||
impl<'a> fmt::Display for AsciiEscaped<'a> { | ||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(fmt, "\"")?; | ||
for byte in self.0.iter().cloned().flat_map(ascii::escape_default) { | ||
write!(fmt, "{}", byte as char)?; | ||
} | ||
write!(fmt, "\"") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We're not going to expose this.
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.
It has previously been stated the tests shouldn't change. To make the tests not change we need to have a blocking windows UDS implementation. Having this requirement only leaves us 2 options.
#[cfg(test)]
to the expose so it can only be used in testsWould option 1 even be allowed? or an Option?
If it isn't an option then if we want windows UDS in tokio there is a requirement for it being implemented in the STD First. Originally it was thought that we could add Windows UDS since MIO already supports Windows Named Pipes without std support.
So is the precedent that std support is required. That is fine, it is nice to just know that is definitly the step forward. Because the only non-std way to fulfill the no-changing-test-requirement would be option 1.
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.
Yes, we need to ensure that the existing behaviour works on Windows as well.
The first option doesn't work as we use Rust's integration tests, which doesn't have access to another crate's
#[cfg(test)]
exposed items. The second option would be ideal, but that's currently not possible as far as I know.You're overlooking a third option. Have a blocking implementation inside the test code.