-
Notifications
You must be signed in to change notification settings - Fork 746
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add first pass implementation of windows uds
modify src/net for windows compatibility fix tests add docs back in cleanup remove log statements clean up selector clean up stream and listener sys logic fix re-registration add test for serial calls to listener.accept fix serial calls to accept remove tempfile dependency and fix doc tests revert change in draining behavior re-organize stdnet files to mirror std::os::unix::net use single syscall vectored approach from rust-lang/socket2 lint improve support across feature matrix fix doc tests use bcrypt instead of rand add -_ to random char set to avoid rejection sampling optimize rng syscall logic fix lint and fmt remove unused functions fmt simplify windows mod clean up tests fix indentation, imports, address other comments fmt remove unrelated code changes fix lint remove explicit SetHandleInformation calls abstract socketaddr behind common API in net fix lint add comment clarifying inheritance during calls to accept
- Loading branch information
1 parent
0757ec8
commit 457f753
Showing
28 changed files
with
1,249 additions
and
299 deletions.
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.