From: Fabian Grünbichler Date: Fri, 4 Dec 2020 10:39:55 +0000 (+0100) Subject: update to tokio 1.0 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=6e02c1221cbea182da76dc564d3d1b0a8424ec0c;p=pxar.git update to tokio 1.0 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 --- 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;