From c81fb04961b7e3059eff086cb2797b03f8cf0f5c Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Sun, 24 Mar 2024 00:01:47 +0800 Subject: [PATCH 1/2] update tokio-rustls. --- client/Cargo.toml | 3 +-- client/src/tls/connector.rs | 3 +-- postgres/src/driver.rs | 2 +- postgres/src/driver/generic.rs | 24 ++++++++++++++++-------- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/client/Cargo.toml b/client/Cargo.toml index 89801f07..e80a12ce 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -50,9 +50,8 @@ openssl-crate = { package = "openssl", version = "0.10", optional = true } tokio-openssl = { version = "0.6.3", optional = true } # rustls, http3 and dangerous features shared support -tokio-rustls = { version = "0.25", optional = true } +tokio-rustls = { version = "0.26", optional = true } webpki-roots = { version = "0.26", optional = true } -rustls-pki-types = "1" # http3 temporary exclusive rustls_0dot21 = { package = "rustls", version = "0.21", optional = true } diff --git a/client/src/tls/connector.rs b/client/src/tls/connector.rs index 320549a1..b7f5f241 100644 --- a/client/src/tls/connector.rs +++ b/client/src/tls/connector.rs @@ -94,9 +94,8 @@ pub(crate) mod openssl { pub(crate) mod rustls { use std::sync::Arc; - use rustls_pki_types::ServerName; use tokio_rustls::{ - rustls::{ClientConfig, RootCertStore}, + rustls::{pki_types::ServerName, ClientConfig, RootCertStore}, TlsConnector, }; use webpki_roots::TLS_SERVER_ROOTS; diff --git a/postgres/src/driver.rs b/postgres/src/driver.rs index ee9bfd2d..ba8ba2cf 100644 --- a/postgres/src/driver.rs +++ b/postgres/src/driver.rs @@ -221,7 +221,7 @@ impl Driver { let tcp = xitca_io::net::io_uring::TcpStream::from_std(std); io_uring::IoUringDriver::new( tcp, - drv.rx, + drv.state.take_rx(), drv.write_buf.into_inner(), drv.read_buf.into_inner(), drv.res, diff --git a/postgres/src/driver/generic.rs b/postgres/src/driver/generic.rs index 516b0150..8b4ec0cd 100644 --- a/postgres/src/driver/generic.rs +++ b/postgres/src/driver/generic.rs @@ -30,16 +30,25 @@ pub(crate) struct GenericDriver { pub(crate) io: Io, pub(crate) write_buf: WriteBuf, pub(crate) read_buf: PagedBytesMut, - pub(crate) rx: GenericDriverRx, + pub(crate) state: DriverState, pub(crate) res: VecDeque, - state: DriverState, } -enum DriverState { - Running, +pub(crate) enum DriverState { + Running(GenericDriverRx), Closing(Option), } +impl DriverState { + #[cfg(feature = "io-uring")] + pub(crate) fn take_rx(self) -> GenericDriverRx { + match self { + Self::Running(rx) => rx, + _ => panic!("driver is closing. no rx can be handed out"), + } + } +} + impl GenericDriver where Io: AsyncIo, @@ -51,9 +60,8 @@ where io, write_buf: WriteBuf::new(), read_buf: PagedBytesMut::new(), - rx, res: VecDeque::new(), - state: DriverState::Running, + state: DriverState::Running(rx), }, tx, ) @@ -72,9 +80,9 @@ where }; let select = match self.state { - DriverState::Running => { + DriverState::Running(ref mut rx) => { let ready = self.io.ready(interest); - self.rx.recv().select(ready).await + rx.recv().select(ready).await } DriverState::Closing(ref mut e) => { if !interest.is_writable() && self.res.is_empty() { From 7657872d2791cc75e086914677c593d33572e6af Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Sun, 24 Mar 2024 00:03:36 +0800 Subject: [PATCH 2/2] clippy fix. --- postgres/src/driver/quic.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/postgres/src/driver/quic.rs b/postgres/src/driver/quic.rs index 81e450dc..f88c9b63 100644 --- a/postgres/src/driver/quic.rs +++ b/postgres/src/driver/quic.rs @@ -4,13 +4,13 @@ mod response; pub use self::response::Response; -use core::{future::Future, pin::Pin}; - -use std::sync::{ - atomic::{AtomicUsize, Ordering}, - Arc, +use core::{ + future::Future, + sync::atomic::{AtomicUsize, Ordering}, }; +use std::sync::Arc; + use postgres_protocol::message::backend; use quinn::{ClientConfig, Connection, Endpoint, ReadError, RecvStream, SendStream}; use quinn_proto::ConnectionError; @@ -222,14 +222,14 @@ impl AsyncLendingIterator for QuicDriver { } impl Drive for QuicDriver { - fn send(&mut self, msg: BytesMut) -> Pin> + Send + '_>> { + fn send(&mut self, msg: BytesMut) -> impl Future> + Send { Box::pin(async move { self.tx.write_all(&msg).await.unwrap(); Ok(()) }) } - fn recv(&mut self) -> Pin> + Send + '_>> { + fn recv(&mut self) -> impl Future> + Send { Box::pin(async move { self.try_next().await?.ok_or_else(|| Error::from(unexpected_eof_err())) }) } }