Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/std/src/os/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
pub mod ffi;
pub mod fs;
pub mod io;
#[unstable(feature = "windows_unix_domain_sockets", issue = "150487")]
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
pub mod net;
pub mod process;
pub mod raw;
Expand Down
13 changes: 7 additions & 6 deletions library/std/src/os/windows/net/addr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![unstable(feature = "windows_unix_domain_sockets", issue = "150487")]
#![stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
use crate::byte_str::ByteStr;
use crate::ffi::OsStr;
use crate::path::Path;
Expand All @@ -8,7 +8,7 @@ use crate::sys::cvt_nz;
use crate::{fmt, io, mem, ptr};

#[cfg(not(doc))]
pub fn sockaddr_un(path: &Path) -> io::Result<(SOCKADDR_UN, usize)> {
pub(super) fn sockaddr_un(path: &Path) -> io::Result<(SOCKADDR_UN, usize)> {
// SAFETY: All zeros is a valid representation for `sockaddr_un`.
let mut addr: SOCKADDR_UN = unsafe { mem::zeroed() };
addr.sun_family = AF_UNIX;
Expand All @@ -34,11 +34,13 @@ pub fn sockaddr_un(path: &Path) -> io::Result<(SOCKADDR_UN, usize)> {
}
#[cfg(not(doc))]
const SUN_PATH_OFFSET: usize = mem::offset_of!(SOCKADDR_UN, sun_path);
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
pub struct SocketAddr {
#[cfg(not(doc))]
pub(super) addr: SOCKADDR_UN,
pub(super) len: u32, // Use u32 here as same as libc::socklen_t
}
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
impl fmt::Debug for SocketAddr {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.address() {
Expand Down Expand Up @@ -81,7 +83,6 @@ impl SocketAddr {
///
#[cfg_attr(windows, doc = "```no_run")]
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
/// #![feature(windows_unix_domain_sockets)]
/// use std::os::windows::net::UnixListener;
/// use std::path::Path;
///
Expand All @@ -92,6 +93,7 @@ impl SocketAddr {
/// Ok(())
/// }
/// ```
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
pub fn as_pathname(&self) -> Option<&Path> {
if let AddressKind::Pathname(path) = self.address() { Some(path) } else { None }
}
Expand All @@ -107,7 +109,6 @@ impl SocketAddr {
///
#[cfg_attr(windows, doc = "```no_run")]
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
/// #![feature(windows_unix_domain_sockets)]
/// use std::os::windows::net::SocketAddr;
/// use std::path::Path;
///
Expand All @@ -122,11 +123,11 @@ impl SocketAddr {
///
#[cfg_attr(windows, doc = "```no_run")]
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
/// #![feature(windows_unix_domain_sockets)]
/// use std::os::windows::net::SocketAddr;
///
/// assert!(SocketAddr::from_pathname("/path/with/\0/bytes").is_err());
/// ```
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
pub fn from_pathname<P>(path: P) -> io::Result<SocketAddr>
where
P: AsRef<Path>,
Expand Down Expand Up @@ -156,7 +157,6 @@ impl SocketAddr {
///
#[cfg_attr(windows, doc = "```no_run")]
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
/// #![feature(windows_unix_domain_sockets)]
/// use std::os::windows::net::UnixListener;
///
/// fn main() -> std::io::Result<()> {
Expand All @@ -166,6 +166,7 @@ impl SocketAddr {
/// Ok(())
/// }
/// ```
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
pub fn is_unnamed(&self) -> bool {
matches!(self.address(), AddressKind::Unnamed)
}
Expand Down
28 changes: 17 additions & 11 deletions library/std/src/os/windows/net/listener.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![unstable(feature = "windows_unix_domain_sockets", issue = "150487")]
#![stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
use crate::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket};
use crate::os::windows::net::{SocketAddr, UnixStream};
use crate::path::Path;
Expand All @@ -18,7 +18,6 @@ use crate::{fmt, io};
///
#[cfg_attr(windows, doc = "```no_run")]
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
/// #![feature(windows_unix_domain_sockets)]
/// use std::thread;
/// use std::os::windows::net::{UnixStream, UnixListener};
///
Expand All @@ -45,8 +44,10 @@ use crate::{fmt, io};
/// Ok(())
/// }
/// ```
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
pub struct UnixListener(Socket);

#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
impl fmt::Debug for UnixListener {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut builder = fmt.debug_struct("UnixListener");
Expand All @@ -64,7 +65,6 @@ impl UnixListener {
///
#[cfg_attr(windows, doc = "```no_run")]
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
/// #![feature(windows_unix_domain_sockets)]
/// use std::os::windows::net::UnixListener;
///
/// let listener = match UnixListener::bind("/path/to/the/socket") {
Expand All @@ -75,6 +75,7 @@ impl UnixListener {
/// }
/// };
/// ```
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
pub fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixListener> {
let socket_addr = SocketAddr::from_pathname(path)?;
Self::bind_addr(&socket_addr)
Expand All @@ -88,7 +89,6 @@ impl UnixListener {
///
#[cfg_attr(windows, doc = "```no_run")]
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
/// #![feature(windows_unix_domain_sockets)]
/// use std::os::windows::net::{UnixListener};
///
/// fn main() -> std::io::Result<()> {
Expand All @@ -105,6 +105,7 @@ impl UnixListener {
/// Ok(())
/// }
/// ```
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
pub fn bind_addr(socket_addr: &SocketAddr) -> io::Result<UnixListener> {
startup();
let inner = Socket::new(AF_UNIX as _, SOCK_STREAM)?;
Expand All @@ -127,7 +128,6 @@ impl UnixListener {
///
#[cfg_attr(windows, doc = "```no_run")]
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
/// #![feature(windows_unix_domain_sockets)]
/// use std::os::windows::net::UnixListener;
///
/// fn main() -> std::io::Result<()> {
Expand All @@ -140,6 +140,7 @@ impl UnixListener {
/// Ok(())
/// }
/// ```
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
pub fn accept(&self) -> io::Result<(UnixStream, SocketAddr)> {
let mut storage = SOCKADDR_UN::default();
let mut len = size_of::<SOCKADDR_UN>() as _;
Expand All @@ -154,7 +155,6 @@ impl UnixListener {
///
#[cfg_attr(windows, doc = "```no_run")]
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
/// #![feature(windows_unix_domain_sockets)]
/// use std::os::windows::net::UnixListener;
///
/// fn main() -> std::io::Result<()> {
Expand All @@ -163,6 +163,7 @@ impl UnixListener {
/// Ok(())
/// }
/// ```
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
pub fn local_addr(&self) -> io::Result<SocketAddr> {
SocketAddr::new(|addr, len| unsafe { getsockname(self.0.as_raw(), addr, len) })
}
Expand All @@ -177,7 +178,6 @@ impl UnixListener {
///
#[cfg_attr(windows, doc = "```no_run")]
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
/// #![feature(windows_unix_domain_sockets)]
/// use std::os::windows::net::UnixListener;
///
/// fn main() -> std::io::Result<()> {
Expand All @@ -186,6 +186,7 @@ impl UnixListener {
/// Ok(())
/// }
/// ```
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
pub fn try_clone(&self) -> io::Result<UnixListener> {
self.0.duplicate().map(UnixListener)
}
Expand All @@ -202,7 +203,6 @@ impl UnixListener {
///
#[cfg_attr(windows, doc = "```no_run")]
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
/// #![feature(windows_unix_domain_sockets)]
/// use std::os::windows::net::UnixListener;
///
/// fn main() -> std::io::Result<()> {
Expand All @@ -211,6 +211,7 @@ impl UnixListener {
/// Ok(())
/// }
/// ```
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
self.0.set_nonblocking(nonblocking)
}
Expand All @@ -221,7 +222,6 @@ impl UnixListener {
///
#[cfg_attr(windows, doc = "```no_run")]
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
/// #![feature(windows_unix_domain_sockets)]
/// use std::os::windows::net::UnixListener;
///
/// fn main() -> std::io::Result<()> {
Expand All @@ -233,6 +233,7 @@ impl UnixListener {
/// Ok(())
/// }
/// ```
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
self.0.take_error()
}
Expand All @@ -246,7 +247,6 @@ impl UnixListener {
///
#[cfg_attr(windows, doc = "```no_run")]
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
/// #![feature(windows_unix_domain_sockets)]
/// use std::thread;
/// use std::os::windows::net::{UnixStream, UnixListener};
///
Expand All @@ -270,6 +270,7 @@ impl UnixListener {
/// Ok(())
/// }
/// ```
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
pub fn incoming(&self) -> Incoming<'_> {
Incoming { listener: self }
}
Expand All @@ -283,7 +284,6 @@ impl UnixListener {
///
#[cfg_attr(windows, doc = "```no_run")]
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
/// #![feature(windows_unix_domain_sockets)]
/// use std::thread;
/// use std::os::windows::net::{UnixStream, UnixListener};
///
Expand All @@ -307,10 +307,12 @@ impl UnixListener {
/// Ok(())
/// }
/// ```
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
pub struct Incoming<'a> {
listener: &'a UnixListener,
}

#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
impl<'a> Iterator for Incoming<'a> {
type Item = io::Result<UnixStream>;

Expand All @@ -323,27 +325,31 @@ impl<'a> Iterator for Incoming<'a> {
}
}

#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
impl AsRawSocket for UnixListener {
#[inline]
fn as_raw_socket(&self) -> RawSocket {
self.0.as_raw_socket()
}
}

#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
impl FromRawSocket for UnixListener {
#[inline]
unsafe fn from_raw_socket(sock: RawSocket) -> Self {
UnixListener(unsafe { Socket::from_raw_socket(sock) })
}
}

#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
impl IntoRawSocket for UnixListener {
#[inline]
fn into_raw_socket(self) -> RawSocket {
self.0.into_raw_socket()
}
}

#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
impl<'a> IntoIterator for &'a UnixListener {
type Item = io::Result<UnixStream>;
type IntoIter = Incoming<'a>;
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/os/windows/net/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
mod addr;
mod listener;
mod stream;
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
pub use addr::*;
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
pub use listener::*;
#[stable(feature = "windows_unix_domain_sockets", since = "CURRENT_RUSTC_VERSION")]
pub use stream::*;
Loading
Loading