diff options
author | Alex Crichton <alex@alexcrichton.com> | 2017-12-05 08:54:48 -0800 |
---|---|---|
committer | Alex Crichton <alex@alexcrichton.com> | 2017-12-05 08:54:48 -0800 |
commit | 46062794aaedf1d2f8385124fa5b7061317a2527 (patch) | |
tree | bbb900a8b7b32733778fd65af132e58cd869e898 | |
parent | 2e584228901db1fd57d68676b4978389fcbecff2 (diff) |
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.
-rw-r--r-- | src/reactor/poll_evented.rs | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/src/reactor/poll_evented.rs b/src/reactor/poll_evented.rs index 382d4155..e3cb1992 100644 --- a/src/reactor/poll_evented.rs +++ b/src/reactor/poll_evented.rs @@ -77,10 +77,12 @@ impl<E: fmt::Debug> fmt::Debug for PollEvented<E> { } } -impl<E: Evented> PollEvented<E> { +impl<E> PollEvented<E> { /// 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<PollEvented<E>> { + pub fn new(io: E, handle: &Handle) -> io::Result<PollEvented<E>> + where E: Evented, + { let token = IoToken::new(&io, handle)?; Ok(PollEvented { @@ -90,29 +92,6 @@ impl<E: Evented> PollEvented<E> { }) } - /// 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<E> PollEvented<E> { /// 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<E> PollEvented<E> { 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<E: Read> Read for PollEvented<E> { |