diff options
author | Carl Lerche <me@carllerche.com> | 2020-10-08 12:12:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-08 12:12:56 -0700 |
commit | 066965cd59d01fd9d999152e32169a24dfe434fa (patch) | |
tree | eef03ca071b8d9f285954a1f98fd85e3e188c98b /tokio/src/io/registration.rs | |
parent | 6259893094ebcdfecb107fcf3682eaad1bd1903b (diff) |
net: use &self with TcpListener::accept (#2919)
Uses the infrastructure added by #2828 to enable switching
`TcpListener::accept` to use `&self`.
This also switches `poll_accept` to use `&self`. While doing introduces
a hazard, `poll_*` style functions are considered low-level. Most users
will use the `async fn` variants which are more misuse-resistant.
TcpListener::incoming() is temporarily removed as it has the same
problem as `TcpSocket::by_ref()` and will be implemented later.
Diffstat (limited to 'tokio/src/io/registration.rs')
-rw-r--r-- | tokio/src/io/registration.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/tokio/src/io/registration.rs b/tokio/src/io/registration.rs index 03221b60..ce6cffda 100644 --- a/tokio/src/io/registration.rs +++ b/tokio/src/io/registration.rs @@ -132,8 +132,19 @@ impl Registration { cfg_io_readiness! { impl Registration { pub(super) async fn readiness(&self, interest: mio::Interest) -> io::Result<ReadyEvent> { - // TODO: does this need to return a `Result`? - Ok(self.shared.readiness(interest).await) + use std::future::Future; + use std::pin::Pin; + + let fut = self.shared.readiness(interest); + pin!(fut); + + crate::future::poll_fn(|cx| { + if self.handle.inner().is_none() { + return Poll::Ready(Err(io::Error::new(io::ErrorKind::Other, "reactor gone"))); + } + + Pin::new(&mut fut).poll(cx).map(Ok) + }).await } } } |