From 0b7ea6b4c879a9e2b9487d13a83b2b2d1b9e729c Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Tue, 2 Jun 2020 16:44:29 +0200 Subject: [PATCH 1/5] set minimum tokio version to 0.2.13 --- Cargo.toml | 2 +- examples/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e5249ca..88a92ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ slab = "0.4.2" socket2 = { version = "0.3.12", features = ["pair", "unix"] } [dependencies.tokio] -version = "0.2.19" +version = "0.2" default-features = false features = ["rt-threaded"] optional = true diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 1ad5539..c0f5d32 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -34,7 +34,7 @@ signal-hook = "0.1.13" smol = { path = "../", features = ["tokio02"] } surf = { version = "2.0.0-alpha.1", default-features = false, features = ["h1-client"] } tempfile = "3.1.0" -tokio = { version = "0.2.18", default-features = false } +tokio = { version = "0.2", default-features = false } tungstenite = "0.10.1" url = "2.1.1" From d43f850050d65de7536d9ccb19a0e3b4a3b8a679 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Wed, 3 Jun 2020 11:38:03 +0200 Subject: [PATCH 2/5] Bump to v0.1.11 --- CHANGELOG.md | 7 +++++++ Cargo.toml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fb70d7..586549a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# Version 0.1.11 + +- Update `wepoll-binding`. +- Reduce dependencies. +- Replace `nix` with `libc`. +- Set minimum required `tokio` version to 0.2. + # Version 0.1.10 - Fix incorrectly reported error kind when connecting fails. diff --git a/Cargo.toml b/Cargo.toml index 88a92ce..d167585 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "smol" -version = "0.1.10" +version = "0.1.11" authors = ["Stjepan Glavina "] edition = "2018" description = "A small and fast async runtime" From e8d0febbc39229736fc86a211537a2dd5681f36f Mon Sep 17 00:00:00 2001 From: Yin Guanhao Date: Sun, 7 Jun 2020 12:00:28 +0200 Subject: [PATCH 3/5] Reregister if we get only readable or writable but we are interested in both. Fix #161. --- src/reactor.rs | 13 +++++++++++ tests/async_io.rs | 59 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/reactor.rs b/src/reactor.rs index c5cd338..11004fc 100644 --- a/src/reactor.rs +++ b/src/reactor.rs @@ -293,6 +293,19 @@ impl ReactorLock<'_> { if ev.writable { ready.append(&mut wakers.writers); } + + // Re-register if there are still writers or + // readers. The can happen if e.g. we were + // previously interested in both readability and + // writability, but only one of them was emitted. + if !(wakers.writers.is_empty() && wakers.readers.is_empty()) { + self.reactor.sys.reregister( + source.raw, + source.key, + !wakers.readers.is_empty(), + !wakers.writers.is_empty(), + )?; + } } } diff --git a/tests/async_io.rs b/tests/async_io.rs index 68c4826..95c3631 100644 --- a/tests/async_io.rs +++ b/tests/async_io.rs @@ -2,7 +2,9 @@ use std::os::unix::net::{UnixDatagram, UnixListener, UnixStream}; use std::{ io, - net::{TcpListener, TcpStream, UdpSocket}, + net::{Shutdown, TcpListener, TcpStream, UdpSocket}, + sync::Arc, + time::Duration, }; use futures::{AsyncReadExt, AsyncWriteExt, StreamExt}; @@ -180,3 +182,58 @@ fn uds_send_to_recv_from() -> io::Result<()> { Ok(()) }) } + +// Test that we correctly re-register interests when we are previously +// interested in both readable and writable events and then we get only one of +// them. (we need to re-register interest on the other.) +#[test] +fn tcp_duplex() -> io::Result<()> { + smol::run(async { + let listener = Async::::bind("127.0.0.1:0")?; + let stream0 = + Arc::new(Async::::connect(listener.get_ref().local_addr()?).await?); + let stream1 = Arc::new(listener.accept().await?.0); + + async fn do_read(s: Arc>) -> io::Result<()> { + let mut buf = vec![0u8; 4096]; + loop { + let len = (&*s).read(&mut buf).await?; + if len == 0 { + return Ok(()); + } + } + } + + async fn do_write(s: Arc>) -> io::Result<()> { + let buf = vec![0u8; 4096]; + for _ in 0..4096 { + (&*s).write_all(&buf).await?; + } + s.get_ref().shutdown(Shutdown::Write)?; + Ok(()) + } + + // Read from and write to stream0. + let r0 = Task::spawn(do_read(stream0.clone())); + let w0 = Task::spawn(do_write(stream0)); + + // Sleep a bit, so that reading and writing are both blocked. + smol::Timer::after(Duration::from_millis(5)).await; + + // Start reading stream1, make stream0 writable. + let r1 = Task::spawn(do_read(stream1.clone())); + + // Finish writing to stream0. + w0.await?; + r1.await?; + + // Start writing to stream1, make stream0 readable. + let w1 = Task::spawn(do_write(stream1)); + + // Will r0 be correctly woken? + r0.await?; + w1.await?; + + Ok(()) + }) +} From 0e6345dd639099718c2a9ff5b998ba8c7981acaa Mon Sep 17 00:00:00 2001 From: Yin Guanhao Date: Sat, 13 Jun 2020 07:28:40 +0200 Subject: [PATCH 4/5] Fix Async::::recv --- src/async_io.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/async_io.rs b/src/async_io.rs index 1178e98..453ae03 100644 --- a/src/async_io.rs +++ b/src/async_io.rs @@ -852,7 +852,7 @@ impl Async { /// # std::io::Result::Ok(()) }); /// ``` pub async fn recv(&self, buf: &mut [u8]) -> io::Result { - self.write_with(|io| io.recv(buf)).await + self.read_with(|io| io.recv(buf)).await } /// Receives a single datagram message from the connected peer without removing it from the From 3f30591a8942d16bf722fffd9468f38866871eff Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Sun, 14 Jun 2020 14:50:38 +0200 Subject: [PATCH 5/5] Bump to v0.1.12 --- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 586549a..27f9c1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# Version 0.1.12 + +- Fix a bug in `Async::::recv()`. + # Version 0.1.11 - Update `wepoll-binding`. diff --git a/Cargo.toml b/Cargo.toml index d167585..c2b6927 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "smol" -version = "0.1.11" +version = "0.1.12" authors = ["Stjepan Glavina "] edition = "2018" description = "A small and fast async runtime"