Skip to content

Commit 5d26a29

Browse files
Merge branch 'master' into fix-detect-connection-fail
2 parents d0f8206 + 77b4ed1 commit 5d26a29

File tree

5 files changed

+55
-23
lines changed

5 files changed

+55
-23
lines changed

.github/workflows/ci.yml

+4
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ jobs:
117117
run: |
118118
rustup target add x86_64-unknown-illumos
119119
cargo build --target x86_64-unknown-illumos
120+
- name: Redox
121+
run: |
122+
rustup target add x86_64-unknown-redox
123+
cargo check --target x86_64-unknown-redox
120124
121125
wine:
122126
runs-on: ubuntu-22.04

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cfg-if = "1"
2222
tracing = { version = "0.1.37", default-features = false }
2323

2424
[target.'cfg(any(unix, target_os = "fuchsia", target_os = "vxworks"))'.dependencies]
25-
rustix = { version = "0.38.8", features = ["event", "fs", "pipe", "process", "std", "time"], default-features = false }
25+
rustix = { version = "0.38.31", features = ["event", "fs", "pipe", "process", "std", "time"], default-features = false }
2626

2727
[target.'cfg(windows)'.dependencies]
2828
concurrent-queue = "2.2.0"

src/epoll.rs

+43-20
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ use std::io;
44
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd};
55
use std::time::Duration;
66

7-
use rustix::event::{epoll, eventfd, EventfdFlags};
8-
use rustix::fd::OwnedFd;
9-
use rustix::fs::{fcntl_getfl, fcntl_setfl, OFlags};
10-
use rustix::io::{fcntl_getfd, fcntl_setfd, read, write, FdFlags};
11-
use rustix::pipe::{pipe, pipe_with, PipeFlags};
7+
#[cfg(not(target_os = "redox"))]
8+
use rustix::event::{eventfd, EventfdFlags};
9+
#[cfg(not(target_os = "redox"))]
1210
use rustix::time::{
1311
timerfd_create, timerfd_settime, Itimerspec, TimerfdClockId, TimerfdFlags, TimerfdTimerFlags,
1412
Timespec,
1513
};
1614

15+
use rustix::event::epoll;
16+
use rustix::fd::OwnedFd;
17+
use rustix::fs::{fcntl_getfl, fcntl_setfl, OFlags};
18+
use rustix::io::{fcntl_getfd, fcntl_setfd, read, write, FdFlags};
19+
use rustix::pipe::{pipe, pipe_with, PipeFlags};
20+
1721
use crate::{Event, PollMode};
1822

1923
/// Interface to epoll.
@@ -26,6 +30,9 @@ pub struct Poller {
2630
notifier: Notifier,
2731

2832
/// File descriptor for the timerfd that produces timeouts.
33+
///
34+
/// Redox does not support timerfd.
35+
#[cfg(not(target_os = "redox"))]
2936
timer_fd: Option<OwnedFd>,
3037
}
3138

@@ -39,6 +46,7 @@ impl Poller {
3946

4047
// Set up notifier and timerfd.
4148
let notifier = Notifier::new()?;
49+
#[cfg(not(target_os = "redox"))]
4250
let timer_fd = timerfd_create(
4351
TimerfdClockId::Monotonic,
4452
TimerfdFlags::CLOEXEC | TimerfdFlags::NONBLOCK,
@@ -48,10 +56,12 @@ impl Poller {
4856
let poller = Poller {
4957
epoll_fd,
5058
notifier,
59+
#[cfg(not(target_os = "redox"))]
5160
timer_fd,
5261
};
5362

5463
unsafe {
64+
#[cfg(not(target_os = "redox"))]
5565
if let Some(ref timer_fd) = poller.timer_fd {
5666
poller.add(
5767
timer_fd.as_raw_fd(),
@@ -70,7 +80,6 @@ impl Poller {
7080
tracing::trace!(
7181
epoll_fd = ?poller.epoll_fd.as_raw_fd(),
7282
notifier = ?poller.notifier,
73-
timer_fd = ?poller.timer_fd,
7483
"new",
7584
);
7685
Ok(poller)
@@ -155,6 +164,7 @@ impl Poller {
155164
);
156165
let _enter = span.enter();
157166

167+
#[cfg(not(target_os = "redox"))]
158168
if let Some(ref timer_fd) = self.timer_fd {
159169
// Configure the timeout using timerfd.
160170
let new_val = Itimerspec {
@@ -181,8 +191,13 @@ impl Poller {
181191
)?;
182192
}
183193

194+
#[cfg(not(target_os = "redox"))]
195+
let timer_fd = &self.timer_fd;
196+
#[cfg(target_os = "redox")]
197+
let timer_fd: Option<core::convert::Infallible> = None;
198+
184199
// Timeout in milliseconds for epoll.
185-
let timeout_ms = match (&self.timer_fd, timeout) {
200+
let timeout_ms = match (timer_fd, timeout) {
186201
(_, Some(t)) if t == Duration::from_secs(0) => 0,
187202
(None, Some(t)) => {
188203
// Round up to a whole millisecond.
@@ -245,10 +260,10 @@ impl Drop for Poller {
245260
"drop",
246261
epoll_fd = ?self.epoll_fd.as_raw_fd(),
247262
notifier = ?self.notifier,
248-
timer_fd = ?self.timer_fd
249263
);
250264
let _enter = span.enter();
251265

266+
#[cfg(not(target_os = "redox"))]
252267
if let Some(timer_fd) = self.timer_fd.take() {
253268
let _ = self.delete(timer_fd.as_fd());
254269
}
@@ -257,6 +272,7 @@ impl Drop for Poller {
257272
}
258273

259274
/// `timespec` value that equals zero.
275+
#[cfg(not(target_os = "redox"))]
260276
const TS_ZERO: Timespec = unsafe { std::mem::transmute([0u8; std::mem::size_of::<Timespec>()]) };
261277

262278
/// Get the EPOLL flags for the interest.
@@ -390,6 +406,7 @@ impl EventExtra {
390406
#[derive(Debug)]
391407
enum Notifier {
392408
/// The primary notifier, using eventfd.
409+
#[cfg(not(target_os = "redox"))]
393410
EventFd(OwnedFd),
394411

395412
/// The fallback notifier, using a pipe.
@@ -406,19 +423,22 @@ impl Notifier {
406423
/// Create a new notifier.
407424
fn new() -> io::Result<Self> {
408425
// Skip eventfd for testing if necessary.
409-
if !cfg!(polling_test_epoll_pipe) {
410-
// Try to create an eventfd.
411-
match eventfd(0, EventfdFlags::CLOEXEC | EventfdFlags::NONBLOCK) {
412-
Ok(fd) => {
413-
tracing::trace!("created eventfd for notifier");
414-
return Ok(Notifier::EventFd(fd));
415-
}
426+
#[cfg(not(target_os = "redox"))]
427+
{
428+
if !cfg!(polling_test_epoll_pipe) {
429+
// Try to create an eventfd.
430+
match eventfd(0, EventfdFlags::CLOEXEC | EventfdFlags::NONBLOCK) {
431+
Ok(fd) => {
432+
tracing::trace!("created eventfd for notifier");
433+
return Ok(Notifier::EventFd(fd));
434+
}
416435

417-
Err(err) => {
418-
tracing::warn!(
419-
"eventfd() failed with error ({}), falling back to pipe",
420-
err
421-
);
436+
Err(err) => {
437+
tracing::warn!(
438+
"eventfd() failed with error ({}), falling back to pipe",
439+
err
440+
);
441+
}
422442
}
423443
}
424444
}
@@ -440,6 +460,7 @@ impl Notifier {
440460
/// The file descriptor to register in the poller.
441461
fn as_fd(&self) -> BorrowedFd<'_> {
442462
match self {
463+
#[cfg(not(target_os = "redox"))]
443464
Notifier::EventFd(fd) => fd.as_fd(),
444465
Notifier::Pipe {
445466
read_pipe: read, ..
@@ -450,6 +471,7 @@ impl Notifier {
450471
/// Notify the poller.
451472
fn notify(&self) {
452473
match self {
474+
#[cfg(not(target_os = "redox"))]
453475
Self::EventFd(fd) => {
454476
let buf: [u8; 8] = 1u64.to_ne_bytes();
455477
let _ = write(fd, &buf);
@@ -464,6 +486,7 @@ impl Notifier {
464486
/// Clear the notification.
465487
fn clear(&self) {
466488
match self {
489+
#[cfg(not(target_os = "redox"))]
467490
Self::EventFd(fd) => {
468491
let mut buf = [0u8; 8];
469492
let _ = read(fd, &mut buf);

src/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Portable interface to epoll, kqueue, event ports, and IOCP.
22
//!
33
//! Supported platforms:
4-
//! - [epoll](https://en.wikipedia.org/wiki/Epoll): Linux, Android
4+
//! - [epoll](https://en.wikipedia.org/wiki/Epoll): Linux, Android, RedoxOS
55
//! - [kqueue](https://en.wikipedia.org/wiki/Kqueue): macOS, iOS, tvOS, watchOS, FreeBSD, NetBSD, OpenBSD,
66
//! DragonFly BSD
77
//! - [event ports](https://illumos.org/man/port_create): illumos, Solaris
@@ -80,7 +80,11 @@ cfg_if! {
8080
if #[cfg(polling_test_poll_backend)] {
8181
mod poll;
8282
use poll as sys;
83-
} else if #[cfg(any(target_os = "linux", target_os = "android"))] {
83+
} else if #[cfg(any(
84+
target_os = "linux",
85+
target_os = "android",
86+
target_os = "redox"
87+
))] {
8488
mod epoll;
8589
use epoll as sys;
8690
} else if #[cfg(any(

src/os.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub mod iocp;
2020

2121
mod __private {
2222
#[doc(hidden)]
23+
#[allow(dead_code)]
2324
pub trait PollerSealed {}
2425

2526
impl PollerSealed for crate::Poller {}

0 commit comments

Comments
 (0)