From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH pxar 1/3] update to tokio 1.0
Date: Tue, 12 Jan 2021 14:58:28 +0100 [thread overview]
Message-ID: <20210112135830.2798301-19-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20210112135830.2798301-1-f.gruenbichler@proxmox.com>
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 <f.gruenbichler@proxmox.com>
---
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<T: Clone + ReadAt> tokio::io::AsyncRead for FileContents<T> {
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context,
- buf: &mut [u8],
- ) -> Poll<io::Result<usize>> {
- Self::do_poll_read(self, cx, buf)
+ buf: &mut tokio::io::ReadBuf,
+ ) -> Poll<io::Result<()>> {
+ 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<T> {
- inner: T,
- }
+#[cfg(feature = "futures-io")]
+mod fut {
+ use std::io;
+ use std::pin::Pin;
+ use std::task::{Context, Poll};
- impl<T: $trait> $name<T> {
- pub fn new(inner: T) -> Self {
- Self { inner }
- }
- }
+ /// Read adapter for `futures::io::AsyncRead`
+ pub struct FuturesReader<T> {
+ inner: T,
+ }
- impl<T: $trait> crate::decoder::SeqRead for $name<T> {
- fn poll_seq_read(
- self: Pin<&mut Self>,
- cx: &mut Context,
- buf: &mut [u8],
- ) -> Poll<io::Result<usize>> {
- unsafe {
- self.map_unchecked_mut(|this| &mut this.inner)
- .poll_read(cx, buf)
- }
- }
+ impl<T: futures::io::AsyncRead> FuturesReader<T> {
+ pub fn new(inner: T) -> Self {
+ Self { inner }
+ }
+ }
+
+ impl<T: futures::io::AsyncRead> crate::decoder::SeqRead for FuturesReader<T> {
+ fn poll_seq_read(
+ self: Pin<&mut Self>,
+ cx: &mut Context,
+ buf: &mut [u8],
+ ) -> Poll<io::Result<usize>> {
+ 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<T> {
+ inner: T,
}
-}
-async_io_impl! {
- #[cfg(feature = "tokio-io")]
- mod tok {
- /// Read adapter for `tokio::io::AsyncRead`.
- TokioReader : tokio::io::AsyncRead;
+ impl<T: tokio::io::AsyncRead> TokioReader<T> {
+ pub fn new(inner: T) -> Self {
+ Self { inner }
+ }
+ }
+
+ impl<T: tokio::io::AsyncRead> crate::decoder::SeqRead for TokioReader<T> {
+ fn poll_seq_read(
+ self: Pin<&mut Self>,
+ cx: &mut Context,
+ buf: &mut [u8],
+ ) -> Poll<io::Result<usize>> {
+ 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
next prev parent reply other threads:[~2021-01-12 13:59 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-12 13:58 [pbs-devel] [PATCH-SERIES 0/20] update to tokio 1.0 and friends Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox 1/4] Cargo.toml: update to tokio 1.0 Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox 2/4] update to rustyline 7 Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox 3/4] update to tokio 1.0 Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox 4/4] tokio 1.0: drop TimeoutFutureExt Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 01/12] update to tokio 1.0 Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 02/12] tokio 1.0: delay -> sleep Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 03/12] proxmox XXX: use tokio::time::timeout directly Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 04/12] tokio 1.0: AsyncRead/Seek with ReadBuf Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 05/12] tokio: adapt to 1.0 runtime changes Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 06/12] tokio: adapt to 1.0 process:Child changes Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 07/12] tokio 1.0: use ReceiverStream from tokio-stream Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 08/12] tokio 1.0: update to new tokio-openssl interface Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 09/12] tokio 1.0: update to new Signal interface Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 10/12] hyper: use new hyper::upgrade Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 11/12] examples: unify h2 examples Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 12/12] cleanup: remove unnecessary 'mut' and '.clone()' Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-fuse] update to tokio 1.0 Fabian Grünbichler
2021-01-12 13:58 ` Fabian Grünbichler [this message]
2021-01-12 13:58 ` [pbs-devel] [RFC pxar 2/3] clippy: use matches! instead of match Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [RFC pxar 3/3] remove futures-io feature Fabian Grünbichler
2021-01-12 14:42 ` Wolfgang Bumiller
2021-01-12 14:52 ` [pbs-devel] [PATCH-SERIES 0/20] update to tokio 1.0 and friends Wolfgang Bumiller
2021-01-14 13:39 ` [pbs-devel] [PATCH proxmox 1/3] fix u2f example Fabian Grünbichler
2021-01-14 13:39 ` [pbs-devel] [PATCH proxmox-backup] proxmox XXX: adapt to moved ParameterSchema Fabian Grünbichler
2021-01-14 13:39 ` [pbs-devel] [PATCH proxmox 2/3] move ParameterSchema from router to schema Fabian Grünbichler
2021-01-14 13:39 ` [pbs-devel] [PATCH proxmox 3/3] build: add autopkgtest target Fabian Grünbichler
2021-01-14 13:41 ` [pbs-devel] [PATCH pxar 1/2] fix example Fabian Grünbichler
2021-01-14 13:41 ` [pbs-devel] [PATCH pxar 2/2] build: fix --no-default-features Fabian Grünbichler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210112135830.2798301-19-f.gruenbichler@proxmox.com \
--to=f.gruenbichler@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.