Skip to content
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

Use consistent cfg attributes #1655

Merged
merged 1 commit into from
Feb 13, 2023
Merged
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
6 changes: 3 additions & 3 deletions src/interest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const WRITABLE: u8 = 0b0010;
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos"
target_os = "macos",
)),
allow(dead_code)
)]
Expand All @@ -45,7 +45,7 @@ impl Interest {
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos"
target_os = "macos",
))]
pub const AIO: Interest = Interest(unsafe { NonZeroU8::new_unchecked(AIO) });

Expand Down Expand Up @@ -152,7 +152,7 @@ impl fmt::Debug for Interest {
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos"
target_os = "macos",
))]
{
if self.is_aio() {
Expand Down
10 changes: 5 additions & 5 deletions src/sys/unix/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ pub(crate) fn new_socket(domain: libc::c_int, socket_type: libc::c_int) -> io::R
target_os = "illumos",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd"
target_os = "openbsd",
))]
let socket_type = socket_type | libc::SOCK_NONBLOCK | libc::SOCK_CLOEXEC;

let socket = syscall!(socket(domain, socket_type, 0))?;

// Mimick `libstd` and set `SO_NOSIGPIPE` on apple systems.
#[cfg(target_vendor = "apple")]
#[cfg(any(target_os = "ios", target_os = "macos"))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, take it or leave it: rust-lang/lang-team#102 also mentions the existence of target_family = "apple", which is set in addition to target_family = "unix" when building for both iOS and macOS. It might be a little bit simpler to use target_family = "apple" here instead?

if let Err(err) = syscall!(setsockopt(
socket,
libc::SOL_SOCKET,
Expand All @@ -40,7 +40,7 @@ pub(crate) fn new_socket(domain: libc::c_int, socket_type: libc::c_int) -> io::R
}

// Darwin doesn't have SOCK_NONBLOCK or SOCK_CLOEXEC.
#[cfg(target_vendor = "apple")]
#[cfg(any(target_os = "ios", target_os = "macos"))]
{
if let Err(err) = syscall!(fcntl(socket, libc::F_SETFL, libc::O_NONBLOCK)) {
let _ = syscall!(close(socket));
Expand Down Expand Up @@ -92,7 +92,7 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, libc::socklen_
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
target_os = "openbsd",
))]
sin_len: 0,
};
Expand All @@ -116,7 +116,7 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, libc::socklen_
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
target_os = "openbsd",
))]
sin6_len: 0,
#[cfg(target_os = "illumos")]
Expand Down
6 changes: 3 additions & 3 deletions src/sys/unix/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ pub fn new() -> io::Result<(Sender, Receiver)> {
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "illumos",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "ios",
target_os = "macos",
target_os = "illumos",
target_os = "redox",
)))]
compile_error!("unsupported target for `mio::unix::pipe`");
Expand Down
33 changes: 16 additions & 17 deletions src/sys/unix/selector/kqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ type Count = libc::size_t;
// Type of the `filter` field in the `kevent` structure.
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))]
type Filter = libc::c_short;
#[cfg(any(target_os = "macos", target_os = "ios"))]
#[cfg(any(target_os = "ios", target_os = "macos"))]
type Filter = i16;
#[cfg(target_os = "netbsd")]
type Filter = u32;

// Type of the `flags` field in the `kevent` structure.
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))]
type Flags = libc::c_ushort;
#[cfg(any(target_os = "macos", target_os = "ios"))]
#[cfg(any(target_os = "ios", target_os = "macos"))]
Comment on lines +24 to +32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly, would target_family="apple" make sense for these?

type Flags = u16;
#[cfg(target_os = "netbsd")]
type Flags = u32;
Expand Down Expand Up @@ -405,7 +405,7 @@ pub mod event {
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos"
target_os = "macos",
))]
{
event.filter == libc::EVFILT_AIO
Expand All @@ -414,7 +414,7 @@ pub mod event {
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos"
target_os = "macos",
)))]
{
false
Expand Down Expand Up @@ -450,7 +450,7 @@ pub mod event {
target_os = "freebsd",
target_os = "dragonfly",
target_os = "ios",
target_os = "macos"
target_os = "macos",
))]
libc::EVFILT_FS,
#[cfg(target_os = "freebsd")]
Expand All @@ -459,7 +459,7 @@ pub mod event {
target_os = "freebsd",
target_os = "dragonfly",
target_os = "ios",
target_os = "macos"
target_os = "macos",
))]
libc::EVFILT_USER,
#[cfg(target_os = "freebsd")]
Expand Down Expand Up @@ -516,49 +516,49 @@ pub mod event {
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos"
target_os = "macos",
))]
libc::NOTE_TRIGGER,
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos"
target_os = "macos",
))]
libc::NOTE_FFNOP,
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos"
target_os = "macos",
))]
libc::NOTE_FFAND,
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos"
target_os = "macos",
))]
libc::NOTE_FFOR,
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos"
target_os = "macos",
))]
libc::NOTE_FFCOPY,
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos"
target_os = "macos",
))]
libc::NOTE_FFCTRLMASK,
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos"
target_os = "macos",
))]
libc::NOTE_FFLAGSMASK,
libc::NOTE_LOWAT,
Expand Down Expand Up @@ -593,21 +593,21 @@ pub mod event {
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
target_os = "openbsd",
))]
libc::NOTE_TRACK,
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
target_os = "openbsd",
))]
libc::NOTE_TRACKERR,
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
target_os = "openbsd",
))]
libc::NOTE_CHILD,
#[cfg(any(target_os = "ios", target_os = "macos"))]
Expand Down Expand Up @@ -635,7 +635,6 @@ pub mod event {
#[cfg(any(target_os = "freebsd", target_os = "ios", target_os = "macos"))]
libc::NOTE_NSECONDS,
#[cfg(any(target_os = "ios", target_os = "macos"))]
#[cfg(any(target_os = "freebsd", target_os = "ios", target_os = "macos"))]
libc::NOTE_ABSOLUTE,
#[cfg(any(target_os = "ios", target_os = "macos"))]
libc::NOTE_LEEWAY,
Expand Down
8 changes: 4 additions & 4 deletions src/sys/unix/selector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ pub(crate) use self::epoll::{event, Event, Events, Selector};
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
))]
mod kqueue;

#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
))]
pub(crate) use self::kqueue::{event, Event, Events, Selector};

Expand Down
11 changes: 4 additions & 7 deletions src/sys/unix/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,13 @@ pub(crate) fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream,
#[cfg(any(
// Android x86's seccomp profile forbids calls to `accept4(2)`
// See https://github.com/tokio-rs/mio/issues/1445 for details
all(
not(target_arch="x86"),
target_os = "android"
),
all(not(target_arch="x86"), target_os = "android"),
target_os = "dragonfly",
target_os = "freebsd",
target_os = "illumos",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd"
target_os = "openbsd",
))]
let stream = {
syscall!(accept4(
Expand All @@ -85,10 +82,10 @@ pub(crate) fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream,
// OSes inherit the non-blocking flag from the listener, so we just have to
// set `CLOEXEC`.
#[cfg(any(
all(target_arch = "x86", target_os = "android"),
target_os = "ios",
target_os = "macos",
target_os = "redox"
target_os = "redox",
all(target_arch = "x86", target_os = "android"),
))]
let stream = {
syscall!(accept(
Expand Down
9 changes: 3 additions & 6 deletions src/sys/unix/uds/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So
target_os = "redox",
// Android x86's seccomp profile forbids calls to `accept4(2)`
// See https://github.com/tokio-rs/mio/issues/1445 for details
all(
target_arch = "x86",
target_os = "android"
)
all(target_arch = "x86", target_os = "android"),
)))]
let socket = {
let flags = libc::SOCK_NONBLOCK | libc::SOCK_CLOEXEC;
Expand All @@ -58,10 +55,10 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So
};

#[cfg(any(
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "redox",
target_os = "ios",
target_os = "macos",
all(target_arch = "x86", target_os = "android")
))]
let socket = syscall!(accept(
Expand Down
2 changes: 1 addition & 1 deletion tests/interest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn fmt_debug() {
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos"
target_os = "macos",
))]
{
assert_eq!(format!("{:?}", Interest::AIO), "AIO");
Expand Down
4 changes: 2 additions & 2 deletions tests/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ pub fn set_linger_zero(socket: &TcpStream) {
libc::setsockopt(
socket.as_raw_fd(),
libc::SOL_SOCKET,
#[cfg(target_vendor = "apple")]
#[cfg(any(target_os = "ios", target_os = "macos"))]
libc::SO_LINGER_SEC,
#[cfg(not(target_vendor = "apple"))]
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
Comment on lines +252 to +254
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I believe we could use target_family = "apple" here?

libc::SO_LINGER,
&val as *const libc::linger as *const libc::c_void,
size_of::<libc::linger>() as libc::socklen_t,
Expand Down
8 changes: 4 additions & 4 deletions tests/win_named_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ fn connect_twice() {
));
t!(poll
.registry()
.register(&mut c1, Token(1), Interest::READABLE | Interest::WRITABLE,));
.register(&mut c1, Token(1), Interest::READABLE | Interest::WRITABLE));
drop(c1);

let mut events = Events::with_capacity(128);
Expand Down Expand Up @@ -290,7 +290,7 @@ fn connect_twice() {
let mut c2 = client(&name);
t!(poll
.registry()
.register(&mut c2, Token(2), Interest::READABLE | Interest::WRITABLE,));
.register(&mut c2, Token(2), Interest::READABLE | Interest::WRITABLE));

'outer: loop {
t!(poll.poll(&mut events, None));
Expand All @@ -311,7 +311,7 @@ fn reregister_deregister_before_register() {

assert_eq!(
poll.registry()
.reregister(&mut pipe, Token(0), Interest::READABLE,)
.reregister(&mut pipe, Token(0), Interest::READABLE)
.unwrap_err()
.kind(),
io::ErrorKind::NotFound,
Expand All @@ -337,7 +337,7 @@ fn reregister_deregister_different_poll() {
assert_eq!(
poll2
.registry()
.reregister(&mut pipe, Token(0), Interest::READABLE,)
.reregister(&mut pipe, Token(0), Interest::READABLE)
.unwrap_err()
.kind(),
io::ErrorKind::AlreadyExists,
Expand Down