Skip to content

Commit

Permalink
Merge branch 'tokio-rs:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinPerez authored May 26, 2024
2 parents d5dc111 + cf52194 commit 997b69c
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 36 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,6 @@ required-features = ["os-poll", "net"]
[[example]]
name = "udp_server"
required-features = ["os-poll", "net"]

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(mio_unsupported_force_poll_poll)', 'cfg(mio_unsupported_force_waker_pipe)'] }
23 changes: 19 additions & 4 deletions src/poll.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#[cfg(all(
unix,
not(mio_unsupported_force_poll_poll),
not(any(target_os = "solaris", target_os = "vita"))
not(any(
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita"
)),
))]
use std::os::unix::io::{AsRawFd, RawFd};
#[cfg(all(debug_assertions, not(target_os = "wasi")))]
Expand Down Expand Up @@ -430,7 +435,12 @@ impl Poll {
#[cfg(all(
unix,
not(mio_unsupported_force_poll_poll),
not(any(target_os = "solaris", target_os = "vita"))
not(any(
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita"
)),
))]
impl AsRawFd for Poll {
fn as_raw_fd(&self) -> RawFd {
Expand Down Expand Up @@ -721,7 +731,12 @@ impl fmt::Debug for Registry {
#[cfg(all(
unix,
not(mio_unsupported_force_poll_poll),
not(any(target_os = "solaris", target_os = "vita"))
not(any(
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita"
)),
))]
impl AsRawFd for Registry {
fn as_raw_fd(&self) -> RawFd {
Expand All @@ -733,7 +748,7 @@ cfg_os_poll! {
#[cfg(all(
unix,
not(mio_unsupported_force_poll_poll),
not(any(target_os = "solaris", target_os = "vita")),
not(any(target_os = "espidf", target_os = "hermit", target_os = "solaris", target_os = "vita")),
))]
#[test]
pub fn as_raw_fd() {
Expand Down
6 changes: 3 additions & 3 deletions src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ cfg_os_poll! {

cfg_io_source! {
// Both `kqueue` and `epoll` don't need to hold any user space state.
#[cfg(not(any(mio_unsupported_force_poll_poll, target_os = "hermit", target_os = "solaris", target_os = "vita")))]
#[cfg(not(any(mio_unsupported_force_poll_poll, target_os = "espidf", target_os = "hermit", target_os = "solaris", target_os = "vita")))]
mod stateless_io_source {
use std::io;
#[cfg(target_os = "hermit")]
Expand Down Expand Up @@ -93,10 +93,10 @@ cfg_os_poll! {
}
}

#[cfg(not(any(mio_unsupported_force_poll_poll, target_os = "hermit", target_os = "solaris",target_os = "vita")))]
#[cfg(not(any(mio_unsupported_force_poll_poll, target_os = "espidf", target_os = "hermit", target_os = "solaris", target_os = "vita")))]
pub(crate) use self::stateless_io_source::IoSourceState;

#[cfg(any(mio_unsupported_force_poll_poll, target_os = "hermit", target_os = "solaris", target_os = "vita"))]
#[cfg(any(mio_unsupported_force_poll_poll, target_os = "espidf", target_os = "hermit", target_os = "solaris", target_os = "vita"))]
pub(crate) use self::selector::IoSourceState;
}

Expand Down
2 changes: 1 addition & 1 deletion src/sys/unix/selector/kqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Selector {

pub fn select(&self, events: &mut Events, timeout: Option<Duration>) -> io::Result<()> {
let timeout = timeout.map(|to| libc::timespec {
tv_sec: cmp::min(to.as_secs(), libc::time_t::max_value() as u64) as libc::time_t,
tv_sec: cmp::min(to.as_secs(), libc::time_t::MAX as u64) as libc::time_t,
// `Duration::subsec_nanos` is guaranteed to be less than one
// billion (the number of nanoseconds in a second), making the
// cast to i32 safe. The cast itself is needed for platforms
Expand Down
14 changes: 11 additions & 3 deletions src/sys/unix/selector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,30 @@ pub(crate) use self::epoll::{event, Event, Events, Selector};

#[cfg(any(
mio_unsupported_force_poll_poll,
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita",
target_os = "hermit"
))]
mod poll;

#[cfg(any(
mio_unsupported_force_poll_poll,
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita",
target_os = "hermit"
))]
pub(crate) use self::poll::{event, Event, Events, Selector};

cfg_io_source! {
#[cfg(any(mio_unsupported_force_poll_poll, target_os = "hermit", target_os = "solaris", target_os = "vita"))]
#[cfg(any(
mio_unsupported_force_poll_poll,
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita",
))]
pub(crate) use self::poll::IoSourceState;
}

Expand Down
13 changes: 7 additions & 6 deletions src/sys/unix/selector/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
// Permission to use this code has been granted by original author:
// https://github.com/tokio-rs/mio/pull/1602#issuecomment-1218441031

use crate::sys::unix::selector::LOWEST_FD;
use crate::sys::unix::waker::WakerInternal;
use crate::{Interest, Token};
use std::collections::HashMap;
use std::fmt::{Debug, Formatter};
#[cfg(target_os = "hermit")]
use std::os::hermit::io::{AsRawFd, RawFd};
#[cfg(unix)]
use std::os::unix::io::{AsRawFd, RawFd};
use std::sync::atomic::AtomicBool;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::{Arc, Condvar, Mutex};
use std::time::Duration;
use std::{cmp, fmt, io};

use crate::sys::unix::selector::LOWEST_FD;
use crate::sys::unix::waker::WakerInternal;
use crate::{Interest, Token};

/// Unique id for use as `SelectorId`.
#[cfg(debug_assertions)]
static NEXT_ID: AtomicUsize = AtomicUsize::new(1);
Expand Down Expand Up @@ -74,6 +74,7 @@ impl Selector {
pub fn wake(&self, token: Token) -> io::Result<()> {
self.state.wake(token)
}

cfg_io_source! {
#[cfg(debug_assertions)]
pub fn id(&self) -> usize {
Expand Down Expand Up @@ -507,7 +508,7 @@ fn poll(fds: &mut [PollFd], timeout: Option<Duration>) -> io::Result<usize> {
#[cfg(target_pointer_width = "32")]
const MAX_SAFE_TIMEOUT: u128 = 1789569;
#[cfg(not(target_pointer_width = "32"))]
const MAX_SAFE_TIMEOUT: u128 = libc::c_int::max_value() as u128;
const MAX_SAFE_TIMEOUT: u128 = libc::c_int::MAX as u128;

let timeout = timeout
.map(|to| {
Expand Down
2 changes: 1 addition & 1 deletion src/sys/unix/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub(crate) fn connect(socket: &net::TcpStream, addr: SocketAddr) -> io::Result<(
}

pub(crate) fn listen(socket: &net::TcpListener, backlog: u32) -> io::Result<()> {
let backlog = backlog.try_into().unwrap_or(i32::max_value());
let backlog = backlog.try_into().unwrap_or(i32::MAX);
syscall!(listen(socket.as_raw_fd(), backlog))?;
Ok(())
}
Expand Down
43 changes: 30 additions & 13 deletions src/sys/unix/waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
target_os = "watchos",
)
)),
not(any(target_os = "solaris", target_os = "vita", target_os = "hermit")),
not(any(
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita"
)),
))]
mod fdbased {
#[cfg(all(
Expand Down Expand Up @@ -65,17 +70,22 @@ mod fdbased {
target_os = "watchos",
)
)),
not(any(target_os = "solaris", target_os = "vita", target_os = "hermit")),
not(any(
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita"
)),
))]
pub use self::fdbased::Waker;

#[cfg(all(
not(mio_unsupported_force_waker_pipe),
any(
target_os = "linux",
target_os = "android",
target_os = "espidf",
target_os = "hermit"
target_os = "hermit",
target_os = "linux",
)
))]
mod eventfd {
Expand Down Expand Up @@ -125,7 +135,11 @@ mod eventfd {
}
}

#[cfg(any(mio_unsupported_force_poll_poll, target_os = "hermit"))]
#[cfg(any(
mio_unsupported_force_poll_poll,
target_os = "espidf",
target_os = "hermit"
))]
pub fn ack_and_reset(&self) {
let _ = self.reset();
}
Expand All @@ -152,15 +166,15 @@ mod eventfd {
}

#[cfg(all(
mio_unsupported_force_poll_poll,
not(mio_unsupported_force_waker_pipe),
any(target_os = "linux", target_os = "android", target_os = "espidf")
any(
mio_unsupported_force_poll_poll,
target_os = "espidf",
target_os = "hermit",
)
))]
pub(crate) use self::eventfd::WakerInternal;

#[cfg(target_os = "hermit")]
pub(crate) use self::eventfd::WakerInternal;

#[cfg(all(
not(mio_unsupported_force_waker_pipe),
any(
Expand Down Expand Up @@ -273,8 +287,9 @@ mod pipe {

#[cfg(any(
mio_unsupported_force_poll_poll,
target_os = "espidf",
target_os = "solaris",
target_os = "vita"
target_os = "vita",
))]
pub fn ack_and_reset(&self) {
self.empty();
Expand Down Expand Up @@ -320,9 +335,10 @@ pub(crate) use self::pipe::WakerInternal;

#[cfg(any(
mio_unsupported_force_poll_poll,
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita",
target_os = "hermit"
))]
mod poll {
use crate::sys::Selector;
Expand Down Expand Up @@ -351,8 +367,9 @@ mod poll {

#[cfg(any(
mio_unsupported_force_poll_poll,
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita",
target_os = "hermit"
))]
pub use self::poll::Waker;
4 changes: 2 additions & 2 deletions src/sys/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl Selector {
}

/// Token used to a add a timeout subscription, also used in removing it again.
const TIMEOUT_TOKEN: wasi::Userdata = wasi::Userdata::max_value();
const TIMEOUT_TOKEN: wasi::Userdata = wasi::Userdata::MAX;

/// Returns a `wasi::Subscription` for `timeout`.
fn timeout_subscription(timeout: Duration) -> wasi::Subscription {
Expand Down Expand Up @@ -334,7 +334,7 @@ pub(crate) mod event {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("EventFdReadwrite")
.field("nbytes", &self.0.nbytes)
.field("flags", &self.0.flags)
.field("flags", &EventrwflagsDetails(self.0.flags))
.finish()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sys/windows/iocp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl CompletionPort {
);
let mut removed = 0;
let timeout = duration_millis(timeout);
let len = cmp::min(list.len(), <u32>::max_value() as usize) as u32;
let len = cmp::min(list.len(), u32::MAX as usize) as u32;
let ret = unsafe {
GetQueuedCompletionStatusEx(
self.handle.raw(),
Expand Down
2 changes: 1 addition & 1 deletion src/sys/windows/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub(crate) fn listen(socket: &net::TcpListener, backlog: u32) -> io::Result<()>
use std::convert::TryInto;
use WinSock::listen;

let backlog = backlog.try_into().unwrap_or(i32::max_value());
let backlog = backlog.try_into().unwrap_or(i32::MAX);
syscall!(
listen(socket.as_raw_socket() as _, backlog),
PartialEq::eq,
Expand Down
2 changes: 1 addition & 1 deletion tests/unix_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ fn unix_stream_shutdown_both() {
let err = stream.write(DATA2).unwrap_err();
#[cfg(unix)]
assert_eq!(err.kind(), io::ErrorKind::BrokenPipe);
#[cfg(window)]
#[cfg(windows)]
assert_eq!(err.kind(), io::ErrorKind::ConnectionAbroted);

// Close the connection to allow the remote to shutdown
Expand Down

0 comments on commit 997b69c

Please sign in to comment.