Skip to content

Commit

Permalink
Use consistent cfg attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomasdezeeuw committed Feb 13, 2023
1 parent 691112d commit 98915ad
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 52 deletions.
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"))]
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"))]
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:/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:/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")))]
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

0 comments on commit 98915ad

Please sign in to comment.