diff --git a/src/hyper.rs b/src/hyper.rs index 8224bcd..a63fe74 100644 --- a/src/hyper.rs +++ b/src/hyper.rs @@ -6,7 +6,7 @@ use std::ops::{Deref, DerefMut}; #[cfg_attr(docsrs, doc(cfg(any(feature = "hyper-h1", feature = "hyper-h2"))))] impl AsyncAccept for AddrIncoming { type Connection = AddrStream; - type Error = io::Error; + type Error = std::io::Error; fn poll_accept( self: Pin<&mut Self>, diff --git a/src/lib.rs b/src/lib.rs index 5d594ca..bf45431 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,7 +20,6 @@ use pin_project_lite::pin_project; #[cfg(feature = "rt")] pub use spawning_handshake::SpawningHandshakes; use std::future::Future; -use std::io; use std::pin::Pin; use std::task::{Context, Poll}; use std::time::Duration; @@ -35,6 +34,9 @@ mod spawning_handshake; #[cfg(any(feature = "hyper-h1", feature = "hyper-h2"))] pub mod hyper; +#[cfg(feature = "tokio-net")] +mod net; + /// Default number of concurrent handshakes pub const DEFAULT_MAX_HANDSHAKES: usize = 64; /// Default timeout for the TLS handshake. @@ -228,7 +230,7 @@ where #[cfg(feature = "rustls")] impl AsyncTls for tokio_rustls::TlsAcceptor { type Stream = tokio_rustls::server::TlsStream; - type Error = io::Error; + type Error = std::io::Error; type AcceptFuture = tokio_rustls::Accept; fn accept(&self, conn: C) -> Self::AcceptFuture { @@ -305,42 +307,6 @@ pub fn builder(tls: T) -> Builder { } } -#[cfg(feature = "tokio-net")] -#[cfg_attr(docsrs, doc(cfg(feature = "tokio-net")))] -impl AsyncAccept for tokio::net::TcpListener { - type Connection = tokio::net::TcpStream; - type Error = io::Error; - - fn poll_accept( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - ) -> Poll>> { - match (*self).poll_accept(cx) { - Poll::Ready(Ok((stream, _))) => Poll::Ready(Some(Ok(stream))), - Poll::Ready(Err(e)) => Poll::Ready(Some(Err(e))), - Poll::Pending => Poll::Pending, - } - } -} - -#[cfg(all(unix, feature = "tokio-net"))] -#[cfg_attr(docsrs, doc(cfg(feature = "tokio-net")))] -impl AsyncAccept for tokio::net::UnixListener { - type Connection = tokio::net::UnixStream; - type Error = io::Error; - - fn poll_accept( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - ) -> Poll>> { - match (*self).poll_accept(cx) { - Poll::Ready(Ok((stream, _))) => Poll::Ready(Some(Ok(stream))), - Poll::Ready(Err(e)) => Poll::Ready(Some(Err(e))), - Poll::Pending => Poll::Pending, - } - } -} - pin_project! { /// See [`AsyncAccept::until`] pub struct Until { diff --git a/src/net.rs b/src/net.rs new file mode 100644 index 0000000..305f308 --- /dev/null +++ b/src/net.rs @@ -0,0 +1,41 @@ +use super::AsyncAccept; +use std::io; +use std::pin::Pin; +use std::task::{Context, Poll}; +use tokio::net::{TcpListener, TcpStream, UnixListener, UnixStream}; + +#[cfg(feature = "tokio-net")] +#[cfg_attr(docsrs, doc(cfg(feature = "tokio-net")))] +impl AsyncAccept for TcpListener { + type Connection = TcpStream; + type Error = io::Error; + + fn poll_accept( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + ) -> Poll>> { + match (*self).poll_accept(cx) { + Poll::Ready(Ok((stream, _))) => Poll::Ready(Some(Ok(stream))), + Poll::Ready(Err(e)) => Poll::Ready(Some(Err(e))), + Poll::Pending => Poll::Pending, + } + } +} + +#[cfg(all(unix, feature = "tokio-net"))] +#[cfg_attr(docsrs, doc(cfg(feature = "tokio-net")))] +impl AsyncAccept for UnixListener { + type Connection = UnixStream; + type Error = io::Error; + + fn poll_accept( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + ) -> Poll>> { + match (*self).poll_accept(cx) { + Poll::Ready(Ok((stream, _))) => Poll::Ready(Some(Ok(stream))), + Poll::Ready(Err(e)) => Poll::Ready(Some(Err(e))), + Poll::Pending => Poll::Pending, + } + } +}