From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 150436775A for ; Tue, 12 Jan 2021 14:59:19 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0C1AD26FF0 for ; Tue, 12 Jan 2021 14:58:49 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 688D526FE5 for ; Tue, 12 Jan 2021 14:58:48 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 3647745637 for ; Tue, 12 Jan 2021 14:58:48 +0100 (CET) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Tue, 12 Jan 2021 14:58:28 +0100 Message-Id: <20210112135830.2798301-19-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210112135830.2798301-1-f.gruenbichler@proxmox.com> References: <20210112135830.2798301-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.223 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_NUMSUBJECT 0.5 Subject ends in numbers excluding current years RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [aio.rs] Subject: [pbs-devel] [PATCH pxar 1/3] update to tokio 1.0 X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Jan 2021 13:59:19 -0000 unfortunately, futures::io::AsyncRead and tokio::io::AsyncRead no longer share a do_poll_read signature, so we need to adapt one to the other (and also no longer generate some wrapper implementations via macro). Signed-off-by: Fabian Grünbichler --- Cargo.toml | 5 +-- src/accessor/aio.rs | 7 +-- src/decoder/aio.rs | 105 ++++++++++++++++++++++++-------------------- 3 files changed, 64 insertions(+), 53 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 24b5489..875de7a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ siphasher = "0.3" anyhow = { version = "1.0", optional = true } futures = { version = "0.3.1", optional = true } -tokio = { version = "0.2.10", optional = true, default-features = false } +tokio = { version = "1.0", optional = true, default-features = false } [target.'cfg(target_os = "linux")'.dependencies] libc = "0.2" @@ -65,8 +65,7 @@ async-example = [ "futures-io", "tokio-io", "tokio-fs", - "tokio/rt-threaded", - "tokio/io-driver", + "tokio/rt-multi-thread", "tokio/macros", ] diff --git a/src/accessor/aio.rs b/src/accessor/aio.rs index a1aaa08..dd017ae 100644 --- a/src/accessor/aio.rs +++ b/src/accessor/aio.rs @@ -410,9 +410,10 @@ impl tokio::io::AsyncRead for FileContents { fn poll_read( self: Pin<&mut Self>, cx: &mut Context, - buf: &mut [u8], - ) -> Poll> { - Self::do_poll_read(self, cx, buf) + buf: &mut tokio::io::ReadBuf, + ) -> Poll> { + Self::do_poll_read(self, cx, &mut buf.initialize_unfilled()) + .map_ok(|bytes| { buf.set_filled(bytes); () }) } } diff --git a/src/decoder/aio.rs b/src/decoder/aio.rs index e7152b3..1a5f5ea 100644 --- a/src/decoder/aio.rs +++ b/src/decoder/aio.rs @@ -136,61 +136,72 @@ mod stream { #[cfg(feature = "futures-io")] pub use stream::DecoderStream; -macro_rules! async_io_impl { - ( - #[cfg( $($attr:tt)+ )] - mod $mod:ident { - $(#[$docs:meta])* - $name:ident : $trait:path ; - } - ) => { - #[cfg( $($attr)+ )] - mod $mod { - use std::io; - use std::pin::Pin; - use std::task::{Context, Poll}; - - $(#[$docs])* - pub struct $name { - inner: T, - } +#[cfg(feature = "futures-io")] +mod fut { + use std::io; + use std::pin::Pin; + use std::task::{Context, Poll}; - impl $name { - pub fn new(inner: T) -> Self { - Self { inner } - } - } + /// Read adapter for `futures::io::AsyncRead` + pub struct FuturesReader { + inner: T, + } - impl crate::decoder::SeqRead for $name { - fn poll_seq_read( - self: Pin<&mut Self>, - cx: &mut Context, - buf: &mut [u8], - ) -> Poll> { - unsafe { - self.map_unchecked_mut(|this| &mut this.inner) - .poll_read(cx, buf) - } - } + impl FuturesReader { + pub fn new(inner: T) -> Self { + Self { inner } + } + } + + impl crate::decoder::SeqRead for FuturesReader { + fn poll_seq_read( + self: Pin<&mut Self>, + cx: &mut Context, + buf: &mut [u8], + ) -> Poll> { + unsafe { + self.map_unchecked_mut(|this| &mut this.inner) + .poll_read(cx, buf) } } - #[cfg( $($attr)+ )] - pub use $mod::$name; } } -async_io_impl! { - #[cfg(feature = "futures-io")] - mod fut { - /// Read adapter for `futures::io::AsyncRead`. - FuturesReader : futures::io::AsyncRead; +#[cfg(feature = "futures-io")] +use fut::FuturesReader; + +#[cfg(feature = "tokio-io")] +mod tok { + use std::io; + use std::pin::Pin; + use std::task::{Context, Poll}; + + /// Read adapter for `futures::io::AsyncRead` + pub struct TokioReader { + inner: T, } -} -async_io_impl! { - #[cfg(feature = "tokio-io")] - mod tok { - /// Read adapter for `tokio::io::AsyncRead`. - TokioReader : tokio::io::AsyncRead; + impl TokioReader { + pub fn new(inner: T) -> Self { + Self { inner } + } + } + + impl crate::decoder::SeqRead for TokioReader { + fn poll_seq_read( + self: Pin<&mut Self>, + cx: &mut Context, + buf: &mut [u8], + ) -> Poll> { + let mut read_buf = tokio::io::ReadBuf::new(buf); + unsafe { + self.map_unchecked_mut(|this| &mut this.inner) + .poll_read(cx, &mut read_buf) + .map_ok(|_| read_buf.filled().len()) + } + } } } + +#[cfg(feature = "tokio-io")] +use tok::TokioReader; -- 2.20.1