From 46062794aaedf1d2f8385124fa5b7061317a2527 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 5 Dec 2017 08:54:48 -0800 Subject: [PATCH] Tweak the `PollEvented::deregister` signature This commit changes the `PollEvented::deregister` signature from fn deregister(self, handle: &Handle) -> io::Result<()> to fn deregister(&self) -> io::Result<()> Now that the handles are `Send` and `Sync` there's no longer any need to pass it in (it's already stored in the `PollEvented` itself). Additionally this switches to `&self` instead of `self` to allow reclamation of the internal resources if necessary. --- src/reactor/poll_evented.rs | 52 +++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/src/reactor/poll_evented.rs b/src/reactor/poll_evented.rs index 382d4155c..e3cb1992a 100644 --- a/src/reactor/poll_evented.rs +++ b/src/reactor/poll_evented.rs @@ -77,10 +77,12 @@ impl fmt::Debug for PollEvented { } } -impl PollEvented { +impl PollEvented { /// Creates a new readiness stream associated with the provided /// `loop_handle` and for the given `source`. - pub fn new(io: E, handle: &Handle) -> io::Result> { + pub fn new(io: E, handle: &Handle) -> io::Result> + where E: Evented, + { let token = IoToken::new(&io, handle)?; Ok(PollEvented { @@ -90,29 +92,6 @@ impl PollEvented { }) } - /// Deregisters this source of events from the reactor core specified. - /// - /// This method can optionally be called to unregister the underlying I/O - /// object with the event loop that the `handle` provided points to. - /// Typically this method is not required as this automatically happens when - /// `E` is dropped, but for some use cases the `E` object doesn't represent - /// an owned reference, so dropping it won't automatically unregister with - /// the event loop. - /// - /// This consumes `self` as it will no longer provide events after the - /// method is called, and will likely return an error if this `PollEvented` - /// was created on a separate event loop from the `handle` specified. - pub fn deregister(self, handle: &Handle) -> io::Result<()> { - let inner = match handle.inner.upgrade() { - Some(inner) => inner, - None => return Ok(()), - }; - - inner.deregister_source(&self.io) - } -} - -impl PollEvented { /// Tests to see if this source is ready to be read from or not. /// /// If this stream is not ready for a read then `Async::NotReady` will be @@ -286,6 +265,29 @@ impl PollEvented { pub fn get_mut(&mut self) -> &mut E { &mut self.io } + + /// Deregisters this source of events from the reactor core specified. + /// + /// This method can optionally be called to unregister the underlying I/O + /// object with the event loop that the `handle` provided points to. + /// Typically this method is not required as this automatically happens when + /// `E` is dropped, but for some use cases the `E` object doesn't represent + /// an owned reference, so dropping it won't automatically unregister with + /// the event loop. + /// + /// This consumes `self` as it will no longer provide events after the + /// method is called, and will likely return an error if this `PollEvented` + /// was created on a separate event loop from the `handle` specified. + pub fn deregister(&self) -> io::Result<()> + where E: Evented, + { + let inner = match self.handle().inner.upgrade() { + Some(inner) => inner, + None => return Ok(()), + }; + + inner.deregister_source(&self.io) + } } impl Read for PollEvented {