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 DCB5B6CFE0 for ; Wed, 31 Mar 2021 13:54:02 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CFFF9EF5C for ; Wed, 31 Mar 2021 13:54:02 +0200 (CEST) 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 718E5EF52 for ; Wed, 31 Mar 2021 13:54:01 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 37DA4427DC for ; Wed, 31 Mar 2021 13:54:01 +0200 (CEST) Date: Wed, 31 Mar 2021 13:54:00 +0200 From: Wolfgang Bumiller To: Stefan Reiter Cc: pbs-devel@lists.proxmox.com Message-ID: <20210331115400.noejnseaamu3essy@wobu-vie.proxmox.com> References: <20210331102202.14767-1-s.reiter@proxmox.com> <20210331102202.14767-2-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210331102202.14767-2-s.reiter@proxmox.com> User-Agent: NeoMutt/20180716 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.028 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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] applied: [PATCH v3 pxar 01/20] decoder/aio: add contents() and content_size() calls 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: Wed, 31 Mar 2021 11:54:02 -0000 applied On Wed, Mar 31, 2021 at 12:21:43PM +0200, Stefan Reiter wrote: > Returns a decoder::Contents without a wrapper type, since in this case > we don't want to hide the SeqRead implementation (as done in > decoder::sync). For conviencience also implement AsyncRead if "tokio-io" > is enabled. > > Signed-off-by: Stefan Reiter > --- > > proxmox-backup requires a dependency bump on this! > > v3: > * assume_init takes just 'n', already calculates offset correctly > > v2: > * make contents() call available without tokio-io feature > * drop peek() implementation > > src/decoder/aio.rs | 36 +++++++++++++++++++++++++++++++++++- > 1 file changed, 35 insertions(+), 1 deletion(-) > > diff --git a/src/decoder/aio.rs b/src/decoder/aio.rs > index 82030b0..55e6464 100644 > --- a/src/decoder/aio.rs > +++ b/src/decoder/aio.rs > @@ -5,7 +5,7 @@ use std::io; > #[cfg(feature = "tokio-fs")] > use std::path::Path; > > -use crate::decoder::{self, SeqRead}; > +use crate::decoder::{self, Contents, SeqRead}; > use crate::Entry; > > /// Asynchronous `pxar` decoder. > @@ -56,6 +56,16 @@ impl Decoder { > self.inner.next_do().await.transpose() > } > > + /// Get a reader for the contents of the current entry, if the entry has contents. > + pub fn contents(&mut self) -> Option> { > + self.inner.content_reader() > + } > + > + /// Get the size of the current contents, if the entry has contents. > + pub fn content_size(&self) -> Option { > + self.inner.content_size() > + } > + > /// Include goodbye tables in iteration. > pub fn enable_goodbye_entries(&mut self, on: bool) { > self.inner.with_goodbye_tables = on; > @@ -67,6 +77,7 @@ mod tok { > use std::io; > use std::pin::Pin; > use std::task::{Context, Poll}; > + use crate::decoder::{Contents, SeqRead}; > > /// Read adapter for `futures::io::AsyncRead` > pub struct TokioReader { > @@ -93,6 +104,29 @@ mod tok { > } > } > } > + > + impl<'a, T: crate::decoder::SeqRead> tokio::io::AsyncRead for Contents<'a, T> { > + fn poll_read( > + self: Pin<&mut Self>, > + cx: &mut Context<'_>, > + buf: &mut tokio::io::ReadBuf<'_>, > + ) -> Poll> { > + unsafe { > + // Safety: poll_seq_read will *probably* only write to the buffer, so we don't > + // initialize it first, instead we treat is a &[u8] immediately and uphold the > + // ReadBuf invariants in the conditional below. > + let write_buf = > + &mut *(buf.unfilled_mut() as *mut [std::mem::MaybeUninit] as *mut [u8]); > + let result = self.poll_seq_read(cx, write_buf); > + if let Poll::Ready(Ok(n)) = result { > + // if we've written data, advance both initialized and filled bytes cursor > + buf.assume_init(n); > + buf.advance(n); > + } > + result.map(|_| Ok(())) > + } > + } > + } > } > > #[cfg(feature = "tokio-io")] > -- > 2.20.1