@@ -87,18 +87,25 @@ impl Reactor {
87
87
#[ cfg( unix) ] raw : RawFd ,
88
88
#[ cfg( windows) ] raw : RawSocket ,
89
89
) -> io:: Result < Arc < Source > > {
90
- // Register the file descriptor.
91
- self . poller . insert ( raw) ?;
92
-
93
90
// Create an I/O source for this file descriptor.
94
- let mut sources = self . sources . lock ( ) . unwrap ( ) ;
95
- let key = sources. next_vacant ( ) ;
96
- let source = Arc :: new ( Source {
97
- raw,
98
- key,
99
- state : Default :: default ( ) ,
100
- } ) ;
101
- sources. insert ( source. clone ( ) ) ;
91
+ let source = {
92
+ let mut sources = self . sources . lock ( ) . unwrap ( ) ;
93
+ let key = sources. next_vacant ( ) ;
94
+ let source = Arc :: new ( Source {
95
+ raw,
96
+ key,
97
+ state : Default :: default ( ) ,
98
+ } ) ;
99
+ sources. insert ( source. clone ( ) ) ;
100
+ source
101
+ } ;
102
+
103
+ // Register the file descriptor.
104
+ if let Err ( err) = self . poller . add ( raw, Event :: none ( source. key ) ) {
105
+ let mut sources = self . sources . lock ( ) . unwrap ( ) ;
106
+ sources. remove ( source. key ) ;
107
+ return Err ( err) ;
108
+ }
102
109
103
110
Ok ( source)
104
111
}
@@ -107,7 +114,7 @@ impl Reactor {
107
114
pub ( crate ) fn remove_io ( & self , source : & Source ) -> io:: Result < ( ) > {
108
115
let mut sources = self . sources . lock ( ) . unwrap ( ) ;
109
116
sources. remove ( source. key ) ;
110
- self . poller . remove ( source. raw )
117
+ self . poller . delete ( source. raw )
111
118
}
112
119
113
120
/// Registers a timer in the reactor.
@@ -283,7 +290,7 @@ impl ReactorLock<'_> {
283
290
// e.g. we were previously interested in both readability and writability,
284
291
// but only one of them was emitted.
285
292
if !state[ READ ] . is_empty ( ) || !state[ WRITE ] . is_empty ( ) {
286
- self . reactor . poller . interest (
293
+ self . reactor . poller . modify (
287
294
source. raw ,
288
295
Event {
289
296
key : source. key ,
@@ -415,7 +422,7 @@ impl Source {
415
422
416
423
// Update interest in this I/O handle.
417
424
if was_empty {
418
- Reactor :: get ( ) . poller . interest (
425
+ Reactor :: get ( ) . poller . modify (
419
426
self . raw ,
420
427
Event {
421
428
key : self . key ,
@@ -466,7 +473,7 @@ impl Source {
466
473
467
474
// Update interest in this I/O handle.
468
475
if was_empty {
469
- Reactor :: get ( ) . poller . interest (
476
+ Reactor :: get ( ) . poller . modify (
470
477
self . raw ,
471
478
Event {
472
479
key : self . key ,
0 commit comments