1
Fork 0

Move conditional compilation to the upper module and sort the target OS list alphabetically

This commit is contained in:
LinkTed 2020-08-28 18:41:48 +02:00
parent 07ed6afc6d
commit 53791b3ff4
4 changed files with 199 additions and 189 deletions

View file

@ -158,10 +158,36 @@ impl<'a, T> Iterator for AncillaryDataIter<'a, T> {
} }
} }
#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_env = "uclibc",
))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "none")] #[unstable(feature = "unix_socket_ancillary_data", issue = "none")]
#[derive(Clone)] #[derive(Clone)]
pub struct UCred(libc::ucred); pub struct UCred(libc::ucred);
#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_env = "uclibc",
))]
impl UCred { impl UCred {
#[unstable(feature = "unix_socket_ancillary_data", issue = "none")] #[unstable(feature = "unix_socket_ancillary_data", issue = "none")]
pub fn new() -> UCred { pub fn new() -> UCred {
@ -199,41 +225,9 @@ impl UCred {
} }
} }
#[cfg(any(
target_os = "haiku",
target_os = "solaris",
target_os = "illumos",
target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "netbsd",
target_os = "linux",
target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_env = "uclibc",
))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "none")] #[unstable(feature = "unix_socket_ancillary_data", issue = "none")]
pub struct ScmRights<'a>(AncillaryDataIter<'a, RawFd>); pub struct ScmRights<'a>(AncillaryDataIter<'a, RawFd>);
#[cfg(any(
target_os = "haiku",
target_os = "solaris",
target_os = "illumos",
target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "netbsd",
target_os = "linux",
target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_env = "uclibc",
))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "none")] #[unstable(feature = "unix_socket_ancillary_data", issue = "none")]
impl<'a> Iterator for ScmRights<'a> { impl<'a> Iterator for ScmRights<'a> {
type Item = RawFd; type Item = RawFd;
@ -244,32 +238,32 @@ impl<'a> Iterator for ScmRights<'a> {
} }
#[cfg(any( #[cfg(any(
target_os = "netbsd", target_os = "android",
target_os = "openbsd",
target_os = "freebsd",
target_os = "dragonfly", target_os = "dragonfly",
target_os = "macos", target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "ios", target_os = "ios",
target_os = "linux", target_os = "linux",
target_os = "android", target_os = "macos",
target_os = "emscripten", target_os = "netbsd",
target_os = "fuchsia", target_os = "openbsd",
target_env = "uclibc", target_env = "uclibc",
))] ))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "none")] #[unstable(feature = "unix_socket_ancillary_data", issue = "none")]
pub struct ScmCredentials<'a>(AncillaryDataIter<'a, libc::ucred>); pub struct ScmCredentials<'a>(AncillaryDataIter<'a, libc::ucred>);
#[cfg(any( #[cfg(any(
target_os = "netbsd", target_os = "android",
target_os = "openbsd",
target_os = "freebsd",
target_os = "dragonfly", target_os = "dragonfly",
target_os = "macos", target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "ios", target_os = "ios",
target_os = "linux", target_os = "linux",
target_os = "android", target_os = "macos",
target_os = "emscripten", target_os = "netbsd",
target_os = "fuchsia", target_os = "openbsd",
target_env = "uclibc", target_env = "uclibc",
))] ))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "none")] #[unstable(feature = "unix_socket_ancillary_data", issue = "none")]
@ -288,58 +282,26 @@ pub enum AncillaryError {
Unknown { cmsg_level: i32, cmsg_type: i32 }, Unknown { cmsg_level: i32, cmsg_type: i32 },
} }
#[cfg(any(
target_os = "haiku",
target_os = "solaris",
target_os = "illumos",
target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "netbsd",
target_os = "linux",
target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_env = "uclibc",
))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "none")] #[unstable(feature = "unix_socket_ancillary_data", issue = "none")]
pub enum AncillaryData<'a> { pub enum AncillaryData<'a> {
ScmRights(ScmRights<'a>), ScmRights(ScmRights<'a>),
#[cfg(any( #[cfg(any(
target_os = "netbsd", target_os = "android",
target_os = "openbsd",
target_os = "freebsd",
target_os = "dragonfly", target_os = "dragonfly",
target_os = "macos", target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "ios", target_os = "ios",
target_os = "linux", target_os = "linux",
target_os = "android", target_os = "macos",
target_os = "emscripten", target_os = "netbsd",
target_os = "fuchsia", target_os = "openbsd",
target_env = "uclibc", target_env = "uclibc",
))] ))]
ScmCredentials(ScmCredentials<'a>), ScmCredentials(ScmCredentials<'a>),
} }
impl<'a> AncillaryData<'a> { impl<'a> AncillaryData<'a> {
#[cfg(any(
target_os = "haiku",
target_os = "solaris",
target_os = "illumos",
target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "netbsd",
target_os = "linux",
target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_env = "uclibc",
))]
fn as_rights(data: &'a [u8]) -> Self { fn as_rights(data: &'a [u8]) -> Self {
let ancillary_data_iter = AncillaryDataIter::new(data); let ancillary_data_iter = AncillaryDataIter::new(data);
let scm_rights = ScmRights(ancillary_data_iter); let scm_rights = ScmRights(ancillary_data_iter);
@ -347,16 +309,16 @@ impl<'a> AncillaryData<'a> {
} }
#[cfg(any( #[cfg(any(
target_os = "netbsd", target_os = "android",
target_os = "openbsd",
target_os = "freebsd",
target_os = "dragonfly", target_os = "dragonfly",
target_os = "macos", target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "ios", target_os = "ios",
target_os = "linux", target_os = "linux",
target_os = "android", target_os = "macos",
target_os = "emscripten", target_os = "netbsd",
target_os = "fuchsia", target_os = "openbsd",
target_env = "uclibc", target_env = "uclibc",
))] ))]
fn as_credentials(data: &'a [u8]) -> Self { fn as_credentials(data: &'a [u8]) -> Self {
@ -365,22 +327,6 @@ impl<'a> AncillaryData<'a> {
AncillaryData::ScmCredentials(scm_credentials) AncillaryData::ScmCredentials(scm_credentials)
} }
#[cfg(any(
target_os = "haiku",
target_os = "solaris",
target_os = "illumos",
target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "netbsd",
target_os = "linux",
target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_env = "uclibc",
))]
fn try_from_cmsghdr(cmsg: &'a libc::cmsghdr) -> Result<Self, AncillaryError> { fn try_from_cmsghdr(cmsg: &'a libc::cmsghdr) -> Result<Self, AncillaryError> {
unsafe { unsafe {
let cmsg_len_zero = libc::CMSG_LEN(0) as usize; let cmsg_len_zero = libc::CMSG_LEN(0) as usize;
@ -392,20 +338,20 @@ impl<'a> AncillaryData<'a> {
libc::SOL_SOCKET => match (*cmsg).cmsg_type { libc::SOL_SOCKET => match (*cmsg).cmsg_type {
libc::SCM_RIGHTS => Ok(AncillaryData::as_rights(data)), libc::SCM_RIGHTS => Ok(AncillaryData::as_rights(data)),
#[cfg(any( #[cfg(any(
target_os = "linux",
target_os = "android", target_os = "android",
target_os = "emscripten", target_os = "emscripten",
target_os = "fuchsia", target_os = "fuchsia",
target_os = "linux",
target_env = "uclibc", target_env = "uclibc",
))] ))]
libc::SCM_CREDENTIALS => Ok(AncillaryData::as_credentials(data)), libc::SCM_CREDENTIALS => Ok(AncillaryData::as_credentials(data)),
#[cfg(any( #[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd", target_os = "netbsd",
target_os = "openbsd", target_os = "openbsd",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "macos",
target_os = "ios",
))] ))]
libc::SCM_CREDS => Ok(AncillaryData::as_credentials(data)), libc::SCM_CREDS => Ok(AncillaryData::as_credentials(data)),
cmsg_type => { cmsg_type => {
@ -420,44 +366,12 @@ impl<'a> AncillaryData<'a> {
} }
} }
#[cfg(any(
target_os = "haiku",
target_os = "solaris",
target_os = "illumos",
target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "netbsd",
target_os = "linux",
target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_env = "uclibc",
))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "none")] #[unstable(feature = "unix_socket_ancillary_data", issue = "none")]
pub struct Messages<'a> { pub struct Messages<'a> {
buffer: &'a [u8], buffer: &'a [u8],
current: Option<&'a libc::cmsghdr>, current: Option<&'a libc::cmsghdr>,
} }
#[cfg(any(
target_os = "haiku",
target_os = "solaris",
target_os = "illumos",
target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "netbsd",
target_os = "linux",
target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_env = "uclibc",
))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "none")] #[unstable(feature = "unix_socket_ancillary_data", issue = "none")]
impl<'a> Iterator for Messages<'a> { impl<'a> Iterator for Messages<'a> {
type Item = Result<AncillaryData<'a>, AncillaryError>; type Item = Result<AncillaryData<'a>, AncillaryError>;
@ -554,22 +468,6 @@ impl<'a> SocketAncillary<'a> {
self.length self.length
} }
#[cfg(any(
target_os = "haiku",
target_os = "solaris",
target_os = "illumos",
target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "netbsd",
target_os = "linux",
target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_env = "uclibc",
))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "none")] #[unstable(feature = "unix_socket_ancillary_data", issue = "none")]
pub fn messages(&self) -> Messages<'_> { pub fn messages(&self) -> Messages<'_> {
Messages { buffer: &self.buffer[..self.length], current: None } Messages { buffer: &self.buffer[..self.length], current: None }
@ -631,22 +529,6 @@ impl<'a> SocketAncillary<'a> {
/// Ok(()) /// Ok(())
/// } /// }
/// ``` /// ```
#[cfg(any(
target_os = "haiku",
target_os = "solaris",
target_os = "illumos",
target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "netbsd",
target_os = "linux",
target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_env = "uclibc",
))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "none")] #[unstable(feature = "unix_socket_ancillary_data", issue = "none")]
pub fn add_fds(&mut self, fds: &[RawFd]) -> bool { pub fn add_fds(&mut self, fds: &[RawFd]) -> bool {
self.truncated = false; self.truncated = false;
@ -667,16 +549,16 @@ impl<'a> SocketAncillary<'a> {
/// and type `SCM_CREDENTIALS`. /// and type `SCM_CREDENTIALS`.
/// ///
#[cfg(any( #[cfg(any(
target_os = "netbsd", target_os = "android",
target_os = "openbsd",
target_os = "freebsd",
target_os = "dragonfly", target_os = "dragonfly",
target_os = "macos", target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "ios", target_os = "ios",
target_os = "linux", target_os = "linux",
target_os = "android", target_os = "macos",
target_os = "emscripten", target_os = "netbsd",
target_os = "fuchsia", target_os = "openbsd",
target_env = "uclibc", target_env = "uclibc",
))] ))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "none")] #[unstable(feature = "unix_socket_ancillary_data", issue = "none")]
@ -688,20 +570,20 @@ impl<'a> SocketAncillary<'a> {
creds, creds,
libc::SOL_SOCKET, libc::SOL_SOCKET,
#[cfg(any( #[cfg(any(
target_os = "linux",
target_os = "android", target_os = "android",
target_os = "emscripten", target_os = "emscripten",
target_os = "fuchsia", target_os = "fuchsia",
target_os = "linux",
target_env = "uclibc", target_env = "uclibc",
))] ))]
libc::SCM_CREDENTIALS, libc::SCM_CREDENTIALS,
#[cfg(any( #[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd", target_os = "netbsd",
target_os = "openbsd", target_os = "openbsd",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "macos",
target_os = "ios",
))] ))]
libc::SCM_CREDS, libc::SCM_CREDS,
) )

View file

@ -4,6 +4,22 @@ use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
use crate::path::Path; use crate::path::Path;
use crate::sys::unix::cvt; use crate::sys::unix::cvt;
use crate::sys::unix::ext::net::addr::{sockaddr_un, SocketAddr}; use crate::sys::unix::ext::net::addr::{sockaddr_un, SocketAddr};
#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "haiku",
target_os = "illumos",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris",
target_env = "uclibc",
))]
use crate::sys::unix::ext::net::ancillary::{ use crate::sys::unix::ext::net::ancillary::{
recv_vectored_with_ancillary_from, send_vectored_with_ancillary_to, SocketAncillary, recv_vectored_with_ancillary_from, send_vectored_with_ancillary_to, SocketAncillary,
}; };
@ -346,6 +362,22 @@ impl UnixDatagram {
/// Ok(()) /// Ok(())
/// } /// }
/// ``` /// ```
#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "haiku",
target_os = "illumos",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris",
target_env = "uclibc",
))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "none")] #[unstable(feature = "unix_socket_ancillary_data", issue = "none")]
pub fn recv_vectored_with_ancillary_from( pub fn recv_vectored_with_ancillary_from(
&self, &self,
@ -394,6 +426,22 @@ impl UnixDatagram {
/// Ok(()) /// Ok(())
/// } /// }
/// ``` /// ```
#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "haiku",
target_os = "illumos",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris",
target_env = "uclibc",
))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "none")] #[unstable(feature = "unix_socket_ancillary_data", issue = "none")]
pub fn recv_vectored_with_ancillary( pub fn recv_vectored_with_ancillary(
&self, &self,

View file

@ -3,6 +3,22 @@
#![stable(feature = "unix_socket", since = "1.10.0")] #![stable(feature = "unix_socket", since = "1.10.0")]
mod addr; mod addr;
#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "haiku",
target_os = "illumos",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris",
target_env = "uclibc",
))]
mod ancillary; mod ancillary;
mod datagram; mod datagram;
mod listener; mod listener;
@ -13,6 +29,22 @@ mod test;
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket", since = "1.10.0")]
pub use self::addr::*; pub use self::addr::*;
#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "haiku",
target_os = "illumos",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris",
target_env = "uclibc",
))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "none")] #[unstable(feature = "unix_socket_ancillary_data", issue = "none")]
pub use self::ancillary::*; pub use self::ancillary::*;
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket", since = "1.10.0")]

View file

@ -16,6 +16,22 @@ use crate::path::Path;
use crate::sys::cvt; use crate::sys::cvt;
use crate::sys::net::Socket; use crate::sys::net::Socket;
use crate::sys::unix::ext::net::addr::{sockaddr_un, SocketAddr}; use crate::sys::unix::ext::net::addr::{sockaddr_un, SocketAddr};
#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "haiku",
target_os = "illumos",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris",
target_env = "uclibc",
))]
use crate::sys::unix::ext::net::ancillary::{ use crate::sys::unix::ext::net::ancillary::{
recv_vectored_with_ancillary_from, send_vectored_with_ancillary_to, SocketAncillary, recv_vectored_with_ancillary_from, send_vectored_with_ancillary_to, SocketAncillary,
}; };
@ -458,6 +474,22 @@ impl UnixStream {
/// Ok(()) /// Ok(())
/// } /// }
/// ``` /// ```
#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "haiku",
target_os = "illumos",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris",
target_env = "uclibc",
))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "none")] #[unstable(feature = "unix_socket_ancillary_data", issue = "none")]
pub fn recv_vectored_with_ancillary( pub fn recv_vectored_with_ancillary(
&self, &self,
@ -498,6 +530,22 @@ impl UnixStream {
/// Ok(()) /// Ok(())
/// } /// }
/// ``` /// ```
#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "haiku",
target_os = "illumos",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris",
target_env = "uclibc",
))]
#[unstable(feature = "unix_socket_ancillary_data", issue = "none")] #[unstable(feature = "unix_socket_ancillary_data", issue = "none")]
pub fn send_vectored_with_ancillary( pub fn send_vectored_with_ancillary(
&self, &self,