@@ -4,16 +4,20 @@ use std::io;
4
4
use std:: os:: unix:: io:: { AsFd , AsRawFd , BorrowedFd , RawFd } ;
5
5
use std:: time:: Duration ;
6
6
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" ) ) ]
12
10
use rustix:: time:: {
13
11
timerfd_create, timerfd_settime, Itimerspec , TimerfdClockId , TimerfdFlags , TimerfdTimerFlags ,
14
12
Timespec ,
15
13
} ;
16
14
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
+
17
21
use crate :: { Event , PollMode } ;
18
22
19
23
/// Interface to epoll.
@@ -26,6 +30,9 @@ pub struct Poller {
26
30
notifier : Notifier ,
27
31
28
32
/// File descriptor for the timerfd that produces timeouts.
33
+ ///
34
+ /// Redox does not support timerfd.
35
+ #[ cfg( not( target_os = "redox" ) ) ]
29
36
timer_fd : Option < OwnedFd > ,
30
37
}
31
38
@@ -39,6 +46,7 @@ impl Poller {
39
46
40
47
// Set up notifier and timerfd.
41
48
let notifier = Notifier :: new ( ) ?;
49
+ #[ cfg( not( target_os = "redox" ) ) ]
42
50
let timer_fd = timerfd_create (
43
51
TimerfdClockId :: Monotonic ,
44
52
TimerfdFlags :: CLOEXEC | TimerfdFlags :: NONBLOCK ,
@@ -48,10 +56,12 @@ impl Poller {
48
56
let poller = Poller {
49
57
epoll_fd,
50
58
notifier,
59
+ #[ cfg( not( target_os = "redox" ) ) ]
51
60
timer_fd,
52
61
} ;
53
62
54
63
unsafe {
64
+ #[ cfg( not( target_os = "redox" ) ) ]
55
65
if let Some ( ref timer_fd) = poller. timer_fd {
56
66
poller. add (
57
67
timer_fd. as_raw_fd ( ) ,
@@ -70,7 +80,6 @@ impl Poller {
70
80
tracing:: trace!(
71
81
epoll_fd = ?poller. epoll_fd. as_raw_fd( ) ,
72
82
notifier = ?poller. notifier,
73
- timer_fd = ?poller. timer_fd,
74
83
"new" ,
75
84
) ;
76
85
Ok ( poller)
@@ -155,6 +164,7 @@ impl Poller {
155
164
) ;
156
165
let _enter = span. enter ( ) ;
157
166
167
+ #[ cfg( not( target_os = "redox" ) ) ]
158
168
if let Some ( ref timer_fd) = self . timer_fd {
159
169
// Configure the timeout using timerfd.
160
170
let new_val = Itimerspec {
@@ -181,8 +191,13 @@ impl Poller {
181
191
) ?;
182
192
}
183
193
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
+
184
199
// Timeout in milliseconds for epoll.
185
- let timeout_ms = match ( & self . timer_fd , timeout) {
200
+ let timeout_ms = match ( timer_fd, timeout) {
186
201
( _, Some ( t) ) if t == Duration :: from_secs ( 0 ) => 0 ,
187
202
( None , Some ( t) ) => {
188
203
// Round up to a whole millisecond.
@@ -245,10 +260,10 @@ impl Drop for Poller {
245
260
"drop" ,
246
261
epoll_fd = ?self . epoll_fd. as_raw_fd( ) ,
247
262
notifier = ?self . notifier,
248
- timer_fd = ?self . timer_fd
249
263
) ;
250
264
let _enter = span. enter ( ) ;
251
265
266
+ #[ cfg( not( target_os = "redox" ) ) ]
252
267
if let Some ( timer_fd) = self . timer_fd . take ( ) {
253
268
let _ = self . delete ( timer_fd. as_fd ( ) ) ;
254
269
}
@@ -257,6 +272,7 @@ impl Drop for Poller {
257
272
}
258
273
259
274
/// `timespec` value that equals zero.
275
+ #[ cfg( not( target_os = "redox" ) ) ]
260
276
const TS_ZERO : Timespec = unsafe { std:: mem:: transmute ( [ 0u8 ; std:: mem:: size_of :: < Timespec > ( ) ] ) } ;
261
277
262
278
/// Get the EPOLL flags for the interest.
@@ -390,6 +406,7 @@ impl EventExtra {
390
406
#[ derive( Debug ) ]
391
407
enum Notifier {
392
408
/// The primary notifier, using eventfd.
409
+ #[ cfg( not( target_os = "redox" ) ) ]
393
410
EventFd ( OwnedFd ) ,
394
411
395
412
/// The fallback notifier, using a pipe.
@@ -406,19 +423,22 @@ impl Notifier {
406
423
/// Create a new notifier.
407
424
fn new ( ) -> io:: Result < Self > {
408
425
// 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
+ }
416
435
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
+ }
422
442
}
423
443
}
424
444
}
@@ -440,6 +460,7 @@ impl Notifier {
440
460
/// The file descriptor to register in the poller.
441
461
fn as_fd ( & self ) -> BorrowedFd < ' _ > {
442
462
match self {
463
+ #[ cfg( not( target_os = "redox" ) ) ]
443
464
Notifier :: EventFd ( fd) => fd. as_fd ( ) ,
444
465
Notifier :: Pipe {
445
466
read_pipe : read, ..
@@ -450,6 +471,7 @@ impl Notifier {
450
471
/// Notify the poller.
451
472
fn notify ( & self ) {
452
473
match self {
474
+ #[ cfg( not( target_os = "redox" ) ) ]
453
475
Self :: EventFd ( fd) => {
454
476
let buf: [ u8 ; 8 ] = 1u64 . to_ne_bytes ( ) ;
455
477
let _ = write ( fd, & buf) ;
@@ -464,6 +486,7 @@ impl Notifier {
464
486
/// Clear the notification.
465
487
fn clear ( & self ) {
466
488
match self {
489
+ #[ cfg( not( target_os = "redox" ) ) ]
467
490
Self :: EventFd ( fd) => {
468
491
let mut buf = [ 0u8 ; 8 ] ;
469
492
let _ = read ( fd, & mut buf) ;
0 commit comments