diff --git a/src/async_io.rs b/src/async_io.rs index 453ae03..9f69f9c 100644 --- a/src/async_io.rs +++ b/src/async_io.rs @@ -159,6 +159,7 @@ impl IntoRawFd for Async { self.into_inner().unwrap().into_raw_fd() } } + #[cfg(windows)] impl Async { /// Creates an async I/O handle. @@ -190,7 +191,7 @@ impl Async { /// use std::net::TcpListener; /// /// # smol::run(async { - /// let listener = TcpListener::bind("127.0.0.1:80")?; + /// let listener = TcpListener::bind("0.0.0.0:0")?; /// let listener = Async::new(listener)?; /// # std::io::Result::Ok(()) }); /// ``` @@ -231,7 +232,7 @@ impl Async { /// use std::net::TcpListener; /// /// # smol::run(async { - /// let listener = Async::::bind("127.0.0.1:80")?; + /// let listener = Async::::bind("0.0.0.0:0")?; /// let inner = listener.get_ref(); /// # std::io::Result::Ok(()) }); /// ``` @@ -248,7 +249,7 @@ impl Async { /// use std::net::TcpListener; /// /// # smol::run(async { - /// let mut listener = Async::::bind("127.0.0.1:80")?; + /// let mut listener = Async::::bind("0.0.0.0:0")?; /// let inner = listener.get_mut(); /// # std::io::Result::Ok(()) }); /// ``` @@ -265,7 +266,7 @@ impl Async { /// use std::net::TcpListener; /// /// # smol::run(async { - /// let listener = Async::::bind("127.0.0.1:80")?; + /// let listener = Async::::bind("0.0.0.0:0")?; /// let inner = listener.into_inner()?; /// # std::io::Result::Ok(()) }); /// ``` @@ -454,6 +455,54 @@ impl Async { self.source.writable().await?; } } + + /// Wait until the async I/O handle is readable. + /// + /// # Examples + /// + /// ``` + /// use smol::Async; + /// use std::net::{TcpListener, TcpStream}; + /// use futures_util::io::AsyncWriteExt; + /// + /// # smol::run(async { + /// let listener = Async::::bind("0.0.0.0:0")?; + /// let addr = listener.get_ref().local_addr()?; + /// + /// let mut stream1 = Async::::connect(addr).await?; + /// let (stream2, _) = listener.accept().await?; + /// + /// stream1.write(b"test").await?; + /// stream2.readable().await?; + /// + /// # std::io::Result::Ok(()) }); + /// ``` + #[inline] + pub async fn readable(&self) -> io::Result<()> { + self.source.readable().await + } + + /// Wait until the async I/O handle is writable. + /// + /// # Examples + /// + /// ``` + /// use smol::Async; + /// use std::net::{TcpListener, TcpStream}; + /// + /// # smol::run(async { + /// let listener = Async::::bind("0.0.0.0:0")?; + /// let addr = listener.get_ref().local_addr()?; + /// + /// let stream = Async::::connect(addr).await?; + /// + /// stream.writable().await?; + /// # std::io::Result::Ok(()) }); + /// ``` + #[inline] + pub async fn writable(&self) -> io::Result<()> { + self.source.writable().await + } } impl Drop for Async {