diff --git a/ntex-connect/Cargo.toml b/ntex-connect/Cargo.toml index 1812294e..49041cba 100644 --- a/ntex-connect/Cargo.toml +++ b/ntex-connect/Cargo.toml @@ -45,7 +45,7 @@ log = "0.4" thiserror = "1.0" ntex-tokio = { version = "0.2.3", optional = true } -ntex-glommio = { version = "0.2.3", optional = true } +ntex-glommio = { version = "0.2.4", optional = true } ntex-async-std = { version = "0.2.2", optional = true } # openssl diff --git a/ntex-glommio/CHANGES.md b/ntex-glommio/CHANGES.md index a6e8c681..4d1bed00 100644 --- a/ntex-glommio/CHANGES.md +++ b/ntex-glommio/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [0.2.4] - 2023-05-30 + +* Fix borrow mut panic #204 + ## [0.2.3] - 2023-04-11 * Chore upgrade glommio to 0.8 diff --git a/ntex-glommio/Cargo.toml b/ntex-glommio/Cargo.toml index 5553a89b..379ce728 100644 --- a/ntex-glommio/Cargo.toml +++ b/ntex-glommio/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ntex-glommio" -version = "0.2.3" +version = "0.2.4" authors = ["ntex contributors "] description = "glommio intergration for ntex framework" keywords = ["network", "framework", "async", "futures"] diff --git a/ntex-glommio/src/io.rs b/ntex-glommio/src/io.rs index 8474e4b4..5950a6d1 100644 --- a/ntex-glommio/src/io.rs +++ b/ntex-glommio/src/io.rs @@ -106,7 +106,8 @@ enum IoWriteState { } enum Shutdown { - None(Pin>>>), + Flush, + Close(Pin>>>), Stopping(u16), } @@ -177,11 +178,7 @@ impl Future for WriteTask { sleep(time) }; - let io = this.io.clone(); - let fut = Box::pin(async move { - io.0.borrow().shutdown(std::net::Shutdown::Write).await - }); - this.st = IoWriteState::Shutdown(timeout, Shutdown::None(fut)); + this.st = IoWriteState::Shutdown(timeout, Shutdown::Flush); self.poll(cx) } Poll::Ready(WriteStatus::Terminate) => { @@ -199,16 +196,18 @@ impl Future for WriteTask { // use disconnect timeout, otherwise it could hang forever. loop { match st { - Shutdown::None(ref mut fut) => { + Shutdown::Flush => { // flush write buffer let mut io = this.io.0.borrow_mut(); match this.state.with_buf(|buf| flush_io(&mut *io, buf, cx)) { Poll::Ready(Ok(())) => { - if ready!(fut.poll(cx)).is_err() { - this.state.close(None); - return Poll::Ready(()); - } - *st = Shutdown::Stopping(0); + let io = this.io.clone(); + let fut = Box::pin(async move { + io.0.borrow() + .shutdown(std::net::Shutdown::Write) + .await + }); + *st = Shutdown::Close(fut); continue; } Poll::Ready(Err(err)) => { @@ -222,6 +221,14 @@ impl Future for WriteTask { Poll::Pending => (), } } + Shutdown::Close(ref mut fut) => { + if ready!(fut.poll(cx)).is_err() { + this.state.close(None); + return Poll::Ready(()); + } + *st = Shutdown::Stopping(0); + continue; + } Shutdown::Stopping(ref mut count) => { // read until 0 or err let mut buf = [0u8; 512]; @@ -479,11 +486,7 @@ impl Future for UnixWriteTask { sleep(time) }; - let io = this.io.clone(); - let fut = Box::pin(async move { - io.0.borrow().shutdown(std::net::Shutdown::Write).await - }); - this.st = IoWriteState::Shutdown(timeout, Shutdown::None(fut)); + this.st = IoWriteState::Shutdown(timeout, Shutdown::Flush); self.poll(cx) } Poll::Ready(WriteStatus::Terminate) => { @@ -501,16 +504,18 @@ impl Future for UnixWriteTask { // use disconnect timeout, otherwise it could hang forever. loop { match st { - Shutdown::None(ref mut fut) => { + Shutdown::Flush => { // flush write buffer let mut io = this.io.0.borrow_mut(); match this.state.with_buf(|buf| flush_io(&mut *io, buf, cx)) { Poll::Ready(Ok(())) => { - if ready!(fut.poll(cx)).is_err() { - this.state.close(None); - return Poll::Ready(()); - } - *st = Shutdown::Stopping(0); + let io = this.io.clone(); + let fut = Box::pin(async move { + io.0.borrow() + .shutdown(std::net::Shutdown::Write) + .await + }); + *st = Shutdown::Close(fut); continue; } Poll::Ready(Err(err)) => { @@ -524,6 +529,14 @@ impl Future for UnixWriteTask { Poll::Pending => (), } } + Shutdown::Close(ref mut fut) => { + if ready!(fut.poll(cx)).is_err() { + this.state.close(None); + return Poll::Ready(()); + } + *st = Shutdown::Stopping(0); + continue; + } Shutdown::Stopping(ref mut count) => { // read until 0 or err let mut buf = [0u8; 512]; diff --git a/ntex-util/src/future/mod.rs b/ntex-util/src/future/mod.rs index eaf9b0a6..1049e5ce 100644 --- a/ntex-util/src/future/mod.rs +++ b/ntex-util/src/future/mod.rs @@ -1,7 +1,7 @@ //! Utilities for futures use std::{future::Future, mem, pin::Pin, task::Context, task::Poll}; -pub use futures_core::Stream; +pub use futures_core::{Stream, TryFuture}; pub use futures_sink::Sink; mod either; diff --git a/ntex/Cargo.toml b/ntex/Cargo.toml index 5a78da5e..3600ba48 100644 --- a/ntex/Cargo.toml +++ b/ntex/Cargo.toml @@ -61,7 +61,7 @@ ntex-rt = "0.4.9" ntex-io = "0.2.10" ntex-tls = "0.2.4" ntex-tokio = { version = "0.2.3", optional = true } -ntex-glommio = { version = "0.2.3", optional = true } +ntex-glommio = { version = "0.2.4", optional = true } ntex-async-std = { version = "0.2.1", optional = true } async-oneshot = "0.5.0"