@@ -15,10 +15,9 @@ use std::time::{Duration, Instant};
15
15
use concurrent_queue:: ConcurrentQueue ;
16
16
use futures_lite:: * ;
17
17
use once_cell:: sync:: Lazy ;
18
+ use polling:: { Event , Poller } ;
18
19
use vec_arena:: Arena ;
19
20
20
- use crate :: sys;
21
-
22
21
/// The reactor.
23
22
///
24
23
/// There is only one global instance of this type, accessible by [`Reactor::get()`].
@@ -29,8 +28,8 @@ pub(crate) struct Reactor {
29
28
/// Unparks the async-io thread.
30
29
thread_unparker : parking:: Unparker ,
31
30
32
- /// Raw bindings to epoll/kqueue/wepoll.
33
- sys : sys :: Reactor ,
31
+ /// Bindings to epoll/kqueue/wepoll.
32
+ poller : Poller ,
34
33
35
34
/// Ticker bumped before polling.
36
35
ticker : AtomicUsize ,
@@ -39,7 +38,7 @@ pub(crate) struct Reactor {
39
38
sources : Mutex < Arena < Arc < Source > > > ,
40
39
41
40
/// Temporary storage for I/O events when polling the reactor.
42
- events : Mutex < sys :: Events > ,
41
+ events : Mutex < Vec < Event > > ,
43
42
44
43
/// An ordered map of registered timers.
45
44
///
@@ -74,10 +73,10 @@ impl Reactor {
74
73
Reactor {
75
74
parker_count : AtomicUsize :: new ( 0 ) ,
76
75
thread_unparker : unparker,
77
- sys : sys :: Reactor :: new ( ) . expect ( "cannot initialize I/O event notification" ) ,
76
+ poller : Poller :: new ( ) . expect ( "cannot initialize I/O event notification" ) ,
78
77
ticker : AtomicUsize :: new ( 0 ) ,
79
78
sources : Mutex :: new ( Arena :: new ( ) ) ,
80
- events : Mutex :: new ( sys :: Events :: new ( ) ) ,
79
+ events : Mutex :: new ( Vec :: new ( ) ) ,
81
80
timers : Mutex :: new ( BTreeMap :: new ( ) ) ,
82
81
timer_ops : ConcurrentQueue :: bounded ( 1000 ) ,
83
82
}
@@ -143,7 +142,7 @@ impl Reactor {
143
142
144
143
/// Notifies the thread blocked on the reactor.
145
144
pub ( crate ) fn notify ( & self ) {
146
- self . sys . notify ( ) . expect ( "failed to notify reactor" ) ;
145
+ self . poller . notify ( ) . expect ( "failed to notify reactor" ) ;
147
146
}
148
147
149
148
/// Registers an I/O source in the reactor.
@@ -153,7 +152,7 @@ impl Reactor {
153
152
#[ cfg( windows) ] raw : RawSocket ,
154
153
) -> io:: Result < Arc < Source > > {
155
154
// Register the file descriptor.
156
- self . sys . insert ( raw) ?;
155
+ self . poller . insert ( raw) ?;
157
156
158
157
// Create an I/O source for this file descriptor.
159
158
let mut sources = self . sources . lock ( ) . unwrap ( ) ;
@@ -177,7 +176,7 @@ impl Reactor {
177
176
pub ( crate ) fn remove_io ( & self , source : & Source ) -> io:: Result < ( ) > {
178
177
let mut sources = self . sources . lock ( ) . unwrap ( ) ;
179
178
sources. remove ( source. key ) ;
180
- self . sys . remove ( source. raw )
179
+ self . poller . remove ( source. raw )
181
180
}
182
181
183
182
/// Registers a timer in the reactor.
@@ -287,7 +286,7 @@ impl Reactor {
287
286
/// A lock on the reactor.
288
287
pub ( crate ) struct ReactorLock < ' a > {
289
288
reactor : & ' a Reactor ,
290
- events : MutexGuard < ' a , sys :: Events > ,
289
+ events : MutexGuard < ' a , Vec < Event > > ,
291
290
}
292
291
293
292
impl ReactorLock < ' _ > {
@@ -313,7 +312,7 @@ impl ReactorLock<'_> {
313
312
. wrapping_add ( 1 ) ;
314
313
315
314
// Block on I/O events.
316
- let res = match self . reactor . sys . wait ( & mut self . events , timeout) {
315
+ let res = match self . reactor . poller . wait ( & mut self . events , timeout) {
317
316
// No I/O events occurred.
318
317
Ok ( 0 ) => {
319
318
if timeout != Some ( Duration :: from_secs ( 0 ) ) {
@@ -350,11 +349,13 @@ impl ReactorLock<'_> {
350
349
// previously interested in both readability and
351
350
// writability, but only one of them was emitted.
352
351
if !( w. writers . is_empty ( ) && w. readers . is_empty ( ) ) {
353
- self . reactor . sys . interest (
352
+ self . reactor . poller . interest (
354
353
source. raw ,
355
- source. key ,
356
- !w. readers . is_empty ( ) ,
357
- !w. writers . is_empty ( ) ,
354
+ Event {
355
+ key : source. key ,
356
+ readable : !w. readers . is_empty ( ) ,
357
+ writable : !w. writers . is_empty ( ) ,
358
+ } ,
358
359
) ?;
359
360
}
360
361
}
@@ -442,9 +443,14 @@ impl Source {
442
443
443
444
// If there are no other readers, re-register in the reactor.
444
445
if w. readers . is_empty ( ) {
445
- Reactor :: get ( )
446
- . sys
447
- . interest ( self . raw , self . key , true , !w. writers . is_empty ( ) ) ?;
446
+ Reactor :: get ( ) . poller . interest (
447
+ self . raw ,
448
+ Event {
449
+ key : self . key ,
450
+ readable : true ,
451
+ writable : !w. writers . is_empty ( ) ,
452
+ } ,
453
+ ) ?;
448
454
}
449
455
450
456
// Register the current task's waker if not present already.
@@ -483,9 +489,14 @@ impl Source {
483
489
484
490
// If there are no other writers, re-register in the reactor.
485
491
if w. writers . is_empty ( ) {
486
- Reactor :: get ( )
487
- . sys
488
- . interest ( self . raw , self . key , !w. readers . is_empty ( ) , true ) ?;
492
+ Reactor :: get ( ) . poller . interest (
493
+ self . raw ,
494
+ Event {
495
+ key : self . key ,
496
+ readable : !w. readers . is_empty ( ) ,
497
+ writable : true ,
498
+ } ,
499
+ ) ?;
489
500
}
490
501
491
502
// Register the current task's waker if not present already.
0 commit comments