1- use io_lifetimes:: BorrowedFd ;
1+ use io_lifetimes:: { AsFd , BorrowedFd } ;
22use std:: { cell:: RefCell , convert:: TryInto , os:: unix:: io:: AsRawFd , rc:: Rc , time:: Duration } ;
33use vec_map:: VecMap ;
44
@@ -243,17 +243,17 @@ impl Poll {
243243 /// If your event source is dropped without being unregistered, the token
244244 /// passed in here will remain on the heap and continue to be used by the
245245 /// polling system even though no event source will match it.
246- pub fn register (
246+ pub fn register < F : AsFd > (
247247 & mut self ,
248- fd : BorrowedFd < ' _ > ,
248+ fd : F ,
249249 interest : Interest ,
250250 mode : Mode ,
251251 token : Token ,
252252 ) -> crate :: Result < ( ) > {
253253 let token_box = Box :: new ( token) ;
254254 let token_ptr = Box :: into_raw ( token_box) ;
255255
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) ;
257257
258258 if registration_result. is_err ( ) {
259259 // If registration did not work, do not add the file descriptor to
@@ -264,15 +264,18 @@ impl Poll {
264264 } else {
265265 // Registration worked, keep the token pointer until it's replaced
266266 // or removed.
267- let index = index_from_fd ( fd) ;
267+ let index = index_from_fd ( fd. as_fd ( ) ) ;
268268 if self . tokens . insert ( index, token_ptr) . is_some ( ) {
269269 // If there is already a file descriptor associated with a
270270 // token, then replacing that entry will leak the token, but
271271 // converting it back into a Box might leave a dangling pointer
272272 // somewhere. We can theoretically continue safely by choosing
273273 // to leak, but one of our assumptions is no longer valid, so
274274 // 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+ ) ;
276279 }
277280 }
278281
@@ -285,17 +288,19 @@ impl Poll {
285288 /// descriptor. Fails if the provided fd is not currently registered.
286289 ///
287290 /// See note on [`register()`](Self::register()) regarding leaking.
288- pub fn reregister (
291+ pub fn reregister < F : AsFd > (
289292 & mut self ,
290- fd : BorrowedFd < ' _ > ,
293+ fd : F ,
291294 interest : Interest ,
292295 mode : Mode ,
293296 token : Token ,
294297 ) -> crate :: Result < ( ) > {
295298 let token_box = Box :: new ( token) ;
296299 let token_ptr = Box :: into_raw ( token_box) ;
297300
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) ;
299304
300305 if reregistration_result. is_err ( ) {
301306 // If registration did not work, do not add the file descriptor to
@@ -306,7 +311,7 @@ impl Poll {
306311 } else {
307312 // Registration worked, drop the old token memory and keep the new
308313 // token pointer until it's replaced or removed.
309- let index = index_from_fd ( fd) ;
314+ let index = index_from_fd ( fd. as_fd ( ) ) ;
310315 if let Some ( previous) = self . tokens . insert ( index, token_ptr) {
311316 // This is safe because it's from Box::into_raw() from a
312317 // previous (re-)register() call.
@@ -321,7 +326,7 @@ impl Poll {
321326 // cannot safely proceed.
322327 panic ! (
323328 "File descriptor ({}) had no previous registration" ,
324- fd. as_raw_fd( )
329+ fd. as_fd ( ) . as_raw_fd( )
325330 ) ;
326331 }
327332 }
@@ -333,12 +338,12 @@ impl Poll {
333338 ///
334339 /// This file descriptor will no longer generate events. Fails if the
335340 /// 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 ( ) ) ;
338343
339344 if unregistration_result. is_ok ( ) {
340345 // 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 ( ) ) ;
342347 if let Some ( previous) = self . tokens . remove ( index) {
343348 // This is safe because it's from Box::into_raw() from a
344349 // previous (re-)register() call.
@@ -353,7 +358,7 @@ impl Poll {
353358 // cannot safely proceed.
354359 panic ! (
355360 "File descriptor ({}) had no previous registration" ,
356- fd. as_raw_fd( )
361+ fd. as_fd ( ) . as_raw_fd( )
357362 ) ;
358363 }
359364 }
0 commit comments