1
- use io_lifetimes:: BorrowedFd ;
1
+ use io_lifetimes:: { AsFd , BorrowedFd } ;
2
2
use std:: { cell:: RefCell , convert:: TryInto , os:: unix:: io:: AsRawFd , rc:: Rc , time:: Duration } ;
3
3
use vec_map:: VecMap ;
4
4
@@ -243,17 +243,17 @@ impl Poll {
243
243
/// If your event source is dropped without being unregistered, the token
244
244
/// passed in here will remain on the heap and continue to be used by the
245
245
/// polling system even though no event source will match it.
246
- pub fn register (
246
+ pub fn register < F : AsFd > (
247
247
& mut self ,
248
- fd : BorrowedFd < ' _ > ,
248
+ fd : F ,
249
249
interest : Interest ,
250
250
mode : Mode ,
251
251
token : Token ,
252
252
) -> crate :: Result < ( ) > {
253
253
let token_box = Box :: new ( token) ;
254
254
let token_ptr = Box :: into_raw ( token_box) ;
255
255
256
- let registration_result = self . poller . register ( fd, interest, mode, token_ptr) ;
256
+ let registration_result = self . poller . register ( fd. as_fd ( ) , interest, mode, token_ptr) ;
257
257
258
258
if registration_result. is_err ( ) {
259
259
// If registration did not work, do not add the file descriptor to
@@ -264,15 +264,18 @@ impl Poll {
264
264
} else {
265
265
// Registration worked, keep the token pointer until it's replaced
266
266
// or removed.
267
- let index = index_from_fd ( fd) ;
267
+ let index = index_from_fd ( fd. as_fd ( ) ) ;
268
268
if self . tokens . insert ( index, token_ptr) . is_some ( ) {
269
269
// If there is already a file descriptor associated with a
270
270
// token, then replacing that entry will leak the token, but
271
271
// converting it back into a Box might leave a dangling pointer
272
272
// somewhere. We can theoretically continue safely by choosing
273
273
// to leak, but one of our assumptions is no longer valid, so
274
274
// panic.
275
- panic ! ( "File descriptor ({}) already registered" , fd. as_raw_fd( ) ) ;
275
+ panic ! (
276
+ "File descriptor ({}) already registered" ,
277
+ fd. as_fd( ) . as_raw_fd( )
278
+ ) ;
276
279
}
277
280
}
278
281
@@ -285,17 +288,19 @@ impl Poll {
285
288
/// descriptor. Fails if the provided fd is not currently registered.
286
289
///
287
290
/// See note on [`register()`](Self::register()) regarding leaking.
288
- pub fn reregister (
291
+ pub fn reregister < F : AsFd > (
289
292
& mut self ,
290
- fd : BorrowedFd < ' _ > ,
293
+ fd : F ,
291
294
interest : Interest ,
292
295
mode : Mode ,
293
296
token : Token ,
294
297
) -> crate :: Result < ( ) > {
295
298
let token_box = Box :: new ( token) ;
296
299
let token_ptr = Box :: into_raw ( token_box) ;
297
300
298
- let reregistration_result = self . poller . reregister ( fd, interest, mode, token_ptr) ;
301
+ let reregistration_result = self
302
+ . poller
303
+ . reregister ( fd. as_fd ( ) , interest, mode, token_ptr) ;
299
304
300
305
if reregistration_result. is_err ( ) {
301
306
// If registration did not work, do not add the file descriptor to
@@ -306,7 +311,7 @@ impl Poll {
306
311
} else {
307
312
// Registration worked, drop the old token memory and keep the new
308
313
// token pointer until it's replaced or removed.
309
- let index = index_from_fd ( fd) ;
314
+ let index = index_from_fd ( fd. as_fd ( ) ) ;
310
315
if let Some ( previous) = self . tokens . insert ( index, token_ptr) {
311
316
// This is safe because it's from Box::into_raw() from a
312
317
// previous (re-)register() call.
@@ -321,7 +326,7 @@ impl Poll {
321
326
// cannot safely proceed.
322
327
panic ! (
323
328
"File descriptor ({}) had no previous registration" ,
324
- fd. as_raw_fd( )
329
+ fd. as_fd ( ) . as_raw_fd( )
325
330
) ;
326
331
}
327
332
}
@@ -333,12 +338,12 @@ impl Poll {
333
338
///
334
339
/// This file descriptor will no longer generate events. Fails if the
335
340
/// provided file descriptor is not currently registered.
336
- pub fn unregister ( & mut self , fd : BorrowedFd < ' _ > ) -> crate :: Result < ( ) > {
337
- let unregistration_result = self . poller . unregister ( fd) ;
341
+ pub fn unregister < F : AsFd > ( & mut self , fd : F ) -> crate :: Result < ( ) > {
342
+ let unregistration_result = self . poller . unregister ( fd. as_fd ( ) ) ;
338
343
339
344
if unregistration_result. is_ok ( ) {
340
345
// The source was unregistered, we can remove the old token data.
341
- let index = index_from_fd ( fd) ;
346
+ let index = index_from_fd ( fd. as_fd ( ) ) ;
342
347
if let Some ( previous) = self . tokens . remove ( index) {
343
348
// This is safe because it's from Box::into_raw() from a
344
349
// previous (re-)register() call.
@@ -353,7 +358,7 @@ impl Poll {
353
358
// cannot safely proceed.
354
359
panic ! (
355
360
"File descriptor ({}) had no previous registration" ,
356
- fd. as_raw_fd( )
361
+ fd. as_fd ( ) . as_raw_fd( )
357
362
) ;
358
363
}
359
364
}
0 commit comments