Skip to content

Add socket extensions for cygwin #139524

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions library/std/src/os/cygwin/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Cygwin-specific definitions
#![stable(feature = "raw_ext", since = "1.1.0")]
pub mod fs;
pub mod net;
pub(crate) mod raw;
10 changes: 10 additions & 0 deletions library/std/src/os/cygwin/net.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//! Cygwin-specific networking functionality.

#![stable(feature = "unix_socket_abstract", since = "1.70.0")]

#[stable(feature = "unix_socket_abstract", since = "1.70.0")]
pub use crate::os::net::linux_ext::addr::SocketAddrExt;
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
pub use crate::os::net::linux_ext::socket::UnixSocketExt;
#[unstable(feature = "tcp_quickack", issue = "96256")]
pub use crate::os::net::linux_ext::tcp::TcpStreamExt;
2 changes: 1 addition & 1 deletion library/std/src/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,5 @@ pub mod xous;
#[cfg(any(unix, target_os = "hermit", target_os = "trusty", target_os = "wasi", doc))]
pub mod fd;

#[cfg(any(target_os = "linux", target_os = "android", doc))]
#[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin", doc))]
mod net;
4 changes: 2 additions & 2 deletions library/std/src/os/net/linux_ext/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Linux and Android-specific networking functionality.
//! Linux, Android and Cygwin-specific networking functionality.

#![doc(cfg(any(target_os = "linux", target_os = "android")))]
#![doc(cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin")))]

#[stable(feature = "unix_socket_abstract", since = "1.70.0")]
pub(crate) mod addr;
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/os/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
all(target_vendor = "fortanix", target_env = "sgx")
)
)))]
#[cfg(any(target_os = "linux", target_os = "android", doc))]
#[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin", doc))]
pub(super) mod linux_ext;
8 changes: 4 additions & 4 deletions library/std/src/os/unix/net/addr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::ffi::OsStr;
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
use crate::os::net::linux_ext;
use crate::os::unix::ffi::OsStrExt;
use crate::path::Path;
Expand Down Expand Up @@ -240,7 +240,7 @@ impl SocketAddr {

// macOS seems to return a len of 16 and a zeroed sun_path for unnamed addresses
if len == 0
|| (cfg!(not(any(target_os = "linux", target_os = "android")))
|| (cfg!(not(any(target_os = "linux", target_os = "android", target_os = "cygwin")))
&& self.addr.sun_path[0] == 0)
{
AddressKind::Unnamed
Expand All @@ -255,8 +255,8 @@ impl SocketAddr {
#[stable(feature = "unix_socket_abstract", since = "1.70.0")]
impl Sealed for SocketAddr {}

#[doc(cfg(any(target_os = "android", target_os = "linux")))]
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
#[doc(cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin")))]
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
#[stable(feature = "unix_socket_abstract", since = "1.70.0")]
impl linux_ext::addr::SocketAddrExt for SocketAddr {
fn as_abstract_name(&self) -> Option<&[u8]> {
Expand Down
31 changes: 19 additions & 12 deletions library/std/src/os/unix/net/ancillary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use crate::sys::net::Socket;
not(target_os = "linux"),
not(target_os = "android"),
not(target_os = "netbsd"),
not(target_os = "freebsd")
not(target_os = "freebsd"),
not(target_os = "cygwin"),
))]
#[allow(non_camel_case_types)]
mod libc {
Expand Down Expand Up @@ -195,14 +196,15 @@ impl<'a, T> Iterator for AncillaryDataIter<'a, T> {
not(target_os = "android"),
not(target_os = "linux"),
not(target_os = "netbsd"),
not(target_os = "freebsd")
not(target_os = "freebsd"),
not(target_os = "cygwin"),
))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
#[derive(Clone)]
pub struct SocketCred(());

/// Unix credential.
#[cfg(any(target_os = "android", target_os = "linux",))]
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
#[derive(Clone)]
pub struct SocketCred(libc::ucred);
Expand All @@ -217,8 +219,8 @@ pub struct SocketCred(libc::sockcred);
#[derive(Clone)]
pub struct SocketCred(libc::sockcred2);

#[doc(cfg(any(target_os = "android", target_os = "linux")))]
#[cfg(any(target_os = "android", target_os = "linux"))]
#[doc(cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin")))]
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
impl SocketCred {
/// Creates a Unix credential struct.
///
Expand Down Expand Up @@ -407,15 +409,16 @@ impl<'a> Iterator for ScmRights<'a> {
not(target_os = "android"),
not(target_os = "linux"),
not(target_os = "netbsd"),
not(target_os = "freebsd")
not(target_os = "freebsd"),
not(target_os = "cygwin"),
))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
pub struct ScmCredentials<'a>(AncillaryDataIter<'a, ()>);

/// This control message contains unix credentials.
///
/// The level is equal to `SOL_SOCKET` and the type is equal to `SCM_CREDENTIALS` or `SCM_CREDS`.
#[cfg(any(target_os = "android", target_os = "linux",))]
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
pub struct ScmCredentials<'a>(AncillaryDataIter<'a, libc::ucred>);

Expand All @@ -432,7 +435,8 @@ pub struct ScmCredentials<'a>(AncillaryDataIter<'a, libc::sockcred>);
target_os = "android",
target_os = "linux",
target_os = "netbsd",
target_os = "freebsd"
target_os = "freebsd",
target_os = "cygwin",
))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
impl<'a> Iterator for ScmCredentials<'a> {
Expand Down Expand Up @@ -460,7 +464,8 @@ pub enum AncillaryData<'a> {
target_os = "android",
target_os = "linux",
target_os = "netbsd",
target_os = "freebsd"
target_os = "freebsd",
target_os = "cygwin",
))]
ScmCredentials(ScmCredentials<'a>),
}
Expand Down Expand Up @@ -489,7 +494,8 @@ impl<'a> AncillaryData<'a> {
target_os = "android",
target_os = "linux",
target_os = "netbsd",
target_os = "freebsd"
target_os = "freebsd",
target_os = "cygwin",
))]
unsafe fn as_credentials(data: &'a [u8]) -> Self {
let ancillary_data_iter = AncillaryDataIter::new(data);
Expand All @@ -507,7 +513,7 @@ impl<'a> AncillaryData<'a> {
match (*cmsg).cmsg_level {
libc::SOL_SOCKET => match (*cmsg).cmsg_type {
libc::SCM_RIGHTS => Ok(AncillaryData::as_rights(data)),
#[cfg(any(target_os = "android", target_os = "linux",))]
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
libc::SCM_CREDENTIALS => Ok(AncillaryData::as_credentials(data)),
#[cfg(target_os = "freebsd")]
libc::SCM_CREDS2 => Ok(AncillaryData::as_credentials(data)),
Expand Down Expand Up @@ -729,7 +735,8 @@ impl<'a> SocketAncillary<'a> {
target_os = "android",
target_os = "linux",
target_os = "netbsd",
target_os = "freebsd"
target_os = "freebsd",
target_os = "cygwin",
))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
pub fn add_creds(&mut self, creds: &[SocketCred]) -> bool {
Expand Down
52 changes: 38 additions & 14 deletions library/std/src/os/unix/net/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use libc::MSG_NOSIGNAL;

use super::{SocketAddr, sockaddr_un};
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
use super::{SocketAncillary, recv_vectored_with_ancillary_from, send_vectored_with_ancillary_to};
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
use crate::io::{IoSlice, IoSliceMut};
use crate::net::Shutdown;
use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
Expand Down Expand Up @@ -397,8 +397,14 @@ impl UnixDatagram {
///
/// # Examples
///
#[cfg_attr(any(target_os = "android", target_os = "linux"), doc = "```no_run")]
#[cfg_attr(not(any(target_os = "android", target_os = "linux")), doc = "```ignore")]
#[cfg_attr(
any(target_os = "android", target_os = "linux", target_os = "cygwin"),
doc = "```no_run"
)]
#[cfg_attr(
not(any(target_os = "android", target_os = "linux", target_os = "cygwin")),
doc = "```ignore"
)]
/// #![feature(unix_socket_ancillary_data)]
/// use std::os::unix::net::{UnixDatagram, SocketAncillary, AncillaryData};
/// use std::io::IoSliceMut;
Expand Down Expand Up @@ -428,7 +434,7 @@ impl UnixDatagram {
/// Ok(())
/// }
/// ```
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
pub fn recv_vectored_with_ancillary_from(
&self,
Expand All @@ -447,8 +453,14 @@ impl UnixDatagram {
///
/// # Examples
///
#[cfg_attr(any(target_os = "android", target_os = "linux"), doc = "```no_run")]
#[cfg_attr(not(any(target_os = "android", target_os = "linux")), doc = "```ignore")]
#[cfg_attr(
any(target_os = "android", target_os = "linux", target_os = "cygwin"),
doc = "```no_run"
)]
#[cfg_attr(
not(any(target_os = "android", target_os = "linux", target_os = "cygwin")),
doc = "```ignore"
)]
/// #![feature(unix_socket_ancillary_data)]
/// use std::os::unix::net::{UnixDatagram, SocketAncillary, AncillaryData};
/// use std::io::IoSliceMut;
Expand Down Expand Up @@ -478,7 +490,7 @@ impl UnixDatagram {
/// Ok(())
/// }
/// ```
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
pub fn recv_vectored_with_ancillary(
&self,
Expand Down Expand Up @@ -588,8 +600,14 @@ impl UnixDatagram {
///
/// # Examples
///
#[cfg_attr(any(target_os = "android", target_os = "linux"), doc = "```no_run")]
#[cfg_attr(not(any(target_os = "android", target_os = "linux")), doc = "```ignore")]
#[cfg_attr(
any(target_os = "android", target_os = "linux", target_os = "cygwin"),
doc = "```no_run"
)]
#[cfg_attr(
not(any(target_os = "android", target_os = "linux", target_os = "cygwin")),
doc = "```ignore"
)]
/// #![feature(unix_socket_ancillary_data)]
/// use std::os::unix::net::{UnixDatagram, SocketAncillary};
/// use std::io::IoSlice;
Expand All @@ -613,7 +631,7 @@ impl UnixDatagram {
/// Ok(())
/// }
/// ```
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
pub fn send_vectored_with_ancillary_to<P: AsRef<Path>>(
&self,
Expand All @@ -630,8 +648,14 @@ impl UnixDatagram {
///
/// # Examples
///
#[cfg_attr(any(target_os = "android", target_os = "linux"), doc = "```no_run")]
#[cfg_attr(not(any(target_os = "android", target_os = "linux")), doc = "```ignore")]
#[cfg_attr(
any(target_os = "android", target_os = "linux", target_os = "cygwin"),
doc = "```no_run"
)]
#[cfg_attr(
not(any(target_os = "android", target_os = "linux", target_os = "cygwin")),
doc = "```ignore"
)]
/// #![feature(unix_socket_ancillary_data)]
/// use std::os::unix::net::{UnixDatagram, SocketAncillary};
/// use std::io::IoSlice;
Expand All @@ -655,7 +679,7 @@ impl UnixDatagram {
/// Ok(())
/// }
/// ```
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
pub fn send_vectored_with_ancillary(
&self,
Expand Down
6 changes: 3 additions & 3 deletions library/std/src/os/unix/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#![stable(feature = "unix_socket", since = "1.10.0")]

mod addr;
#[doc(cfg(any(target_os = "android", target_os = "linux")))]
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
#[doc(cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin")))]
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
mod ancillary;
mod datagram;
mod listener;
Expand All @@ -27,7 +27,7 @@ mod ucred;

#[stable(feature = "unix_socket", since = "1.10.0")]
pub use self::addr::*;
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
pub use self::ancillary::*;
#[stable(feature = "unix_socket", since = "1.10.0")]
Expand Down
26 changes: 19 additions & 7 deletions library/std/src/os/unix/net/stream.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{SocketAddr, sockaddr_un};
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
use super::{SocketAncillary, recv_vectored_with_ancillary_from, send_vectored_with_ancillary_to};
#[cfg(any(
target_os = "android",
Expand Down Expand Up @@ -485,8 +485,14 @@ impl UnixStream {
///
/// # Examples
///
#[cfg_attr(any(target_os = "android", target_os = "linux"), doc = "```no_run")]
#[cfg_attr(not(any(target_os = "android", target_os = "linux")), doc = "```ignore")]
#[cfg_attr(
any(target_os = "android", target_os = "linux", target_os = "cygwin"),
doc = "```no_run"
)]
#[cfg_attr(
not(any(target_os = "android", target_os = "linux", target_os = "cygwin")),
doc = "```ignore"
)]
/// #![feature(unix_socket_ancillary_data)]
/// use std::os::unix::net::{UnixStream, SocketAncillary, AncillaryData};
/// use std::io::IoSliceMut;
Expand Down Expand Up @@ -516,7 +522,7 @@ impl UnixStream {
/// Ok(())
/// }
/// ```
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
pub fn recv_vectored_with_ancillary(
&self,
Expand All @@ -534,8 +540,14 @@ impl UnixStream {
///
/// # Examples
///
#[cfg_attr(any(target_os = "android", target_os = "linux"), doc = "```no_run")]
#[cfg_attr(not(any(target_os = "android", target_os = "linux")), doc = "```ignore")]
#[cfg_attr(
any(target_os = "android", target_os = "linux", target_os = "cygwin"),
doc = "```no_run"
)]
#[cfg_attr(
not(any(target_os = "android", target_os = "linux", target_os = "cygwin")),
doc = "```ignore"
)]
/// #![feature(unix_socket_ancillary_data)]
/// use std::os::unix::net::{UnixStream, SocketAncillary};
/// use std::io::IoSlice;
Expand All @@ -559,7 +571,7 @@ impl UnixStream {
/// Ok(())
/// }
/// ```
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
pub fn send_vectored_with_ancillary(
&self,
Expand Down
Loading
Loading