update to tokio 1.0
and switch from PollEvented to AsyncFd, dropping the direct mio dependency in turn. Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com> Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
29219349a6
commit
7a1ab2b21e
@ -17,5 +17,4 @@ anyhow = "1.0"
|
|||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
nix = "0.19"
|
nix = "0.19"
|
||||||
mio = "0.6.21"
|
tokio = { version = "1.0", features = [ "rt-multi-thread", "io-util", "net" ] }
|
||||||
tokio = { version = "0.2.9", features = [ "rt-threaded", "io-driver", "io-util" ] }
|
|
||||||
|
@ -5,7 +5,7 @@ use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
|
|||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use tokio::io::{AsyncRead, AsyncWrite};
|
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
|
||||||
|
|
||||||
use crate::error::io_err_other;
|
use crate::error::io_err_other;
|
||||||
use crate::io::polled_fd::PolledFd;
|
use crate::io::polled_fd::PolledFd;
|
||||||
@ -86,13 +86,14 @@ impl<RW: rw_traits::HasRead> AsyncRead for Pipe<RW> {
|
|||||||
fn poll_read(
|
fn poll_read(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
buf: &mut [u8],
|
buf: &mut ReadBuf,
|
||||||
) -> Poll<io::Result<usize>> {
|
) -> Poll<io::Result<()>> {
|
||||||
self.fd.wrap_read(cx, || {
|
self.fd.wrap_read(cx, || {
|
||||||
let fd = self.as_raw_fd();
|
let fd = self.as_raw_fd();
|
||||||
|
let buf = buf.initialize_unfilled();
|
||||||
let size = libc::size_t::try_from(buf.len()).map_err(io_err_other)?;
|
let size = libc::size_t::try_from(buf.len()).map_err(io_err_other)?;
|
||||||
c_result!(unsafe { libc::read(fd, buf.as_mut_ptr() as *mut libc::c_void, size) })
|
c_result!(unsafe { libc::read(fd, buf.as_mut_ptr() as *mut libc::c_void, size) })
|
||||||
.map(|res| res as usize)
|
.map(|_| ())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,7 @@ use std::io;
|
|||||||
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
|
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use mio::event::Evented;
|
use tokio::io::unix::AsyncFd;
|
||||||
use mio::unix::EventedFd as MioEventedFd;
|
|
||||||
use mio::Poll as MioPoll;
|
|
||||||
use mio::{PollOpt, Ready, Token};
|
|
||||||
use tokio::io::PollEvented;
|
|
||||||
|
|
||||||
use crate::tools::Fd;
|
use crate::tools::Fd;
|
||||||
|
|
||||||
@ -43,41 +39,15 @@ impl IntoRawFd for EventedFd {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Evented for EventedFd {
|
|
||||||
fn register(
|
|
||||||
&self,
|
|
||||||
poll: &MioPoll,
|
|
||||||
token: Token,
|
|
||||||
interest: Ready,
|
|
||||||
opts: PollOpt,
|
|
||||||
) -> io::Result<()> {
|
|
||||||
MioEventedFd(self.fd.as_ref()).register(poll, token, interest, opts)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn reregister(
|
|
||||||
&self,
|
|
||||||
poll: &MioPoll,
|
|
||||||
token: Token,
|
|
||||||
interest: Ready,
|
|
||||||
opts: PollOpt,
|
|
||||||
) -> io::Result<()> {
|
|
||||||
MioEventedFd(self.fd.as_ref()).reregister(poll, token, interest, opts)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn deregister(&self, poll: &MioPoll) -> io::Result<()> {
|
|
||||||
MioEventedFd(self.fd.as_ref()).deregister(poll)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct PolledFd {
|
pub struct PolledFd {
|
||||||
fd: PollEvented<EventedFd>,
|
fd: AsyncFd<EventedFd>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PolledFd {
|
impl PolledFd {
|
||||||
pub fn new(fd: Fd) -> tokio::io::Result<Self> {
|
pub fn new(fd: Fd) -> tokio::io::Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
fd: PollEvented::new(EventedFd::new(fd))?,
|
fd: AsyncFd::new(EventedFd::new(fd))?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,11 +56,11 @@ impl PolledFd {
|
|||||||
cx: &mut Context,
|
cx: &mut Context,
|
||||||
func: impl FnOnce() -> io::Result<T>,
|
func: impl FnOnce() -> io::Result<T>,
|
||||||
) -> Poll<io::Result<T>> {
|
) -> Poll<io::Result<T>> {
|
||||||
ready!(self.fd.poll_read_ready(cx, mio::Ready::readable()))?;
|
let mut ready_guard = ready!(self.fd.poll_read_ready(cx))?;
|
||||||
match func() {
|
match func() {
|
||||||
Ok(out) => Poll::Ready(Ok(out)),
|
Ok(out) => Poll::Ready(Ok(out)),
|
||||||
Err(ref err) if err.kind() == io::ErrorKind::WouldBlock => {
|
Err(ref err) if err.kind() == io::ErrorKind::WouldBlock => {
|
||||||
self.fd.clear_read_ready(cx, mio::Ready::readable())?;
|
ready_guard.clear_ready();
|
||||||
Poll::Pending
|
Poll::Pending
|
||||||
}
|
}
|
||||||
Err(err) => Poll::Ready(Err(err)),
|
Err(err) => Poll::Ready(Err(err)),
|
||||||
@ -102,11 +72,11 @@ impl PolledFd {
|
|||||||
cx: &mut Context,
|
cx: &mut Context,
|
||||||
func: impl FnOnce() -> io::Result<T>,
|
func: impl FnOnce() -> io::Result<T>,
|
||||||
) -> Poll<io::Result<T>> {
|
) -> Poll<io::Result<T>> {
|
||||||
ready!(self.fd.poll_write_ready(cx))?;
|
let mut ready_guard = ready!(self.fd.poll_write_ready(cx))?;
|
||||||
match func() {
|
match func() {
|
||||||
Ok(out) => Poll::Ready(Ok(out)),
|
Ok(out) => Poll::Ready(Ok(out)),
|
||||||
Err(ref err) if err.kind() == io::ErrorKind::WouldBlock => {
|
Err(ref err) if err.kind() == io::ErrorKind::WouldBlock => {
|
||||||
self.fd.clear_write_ready(cx)?;
|
ready_guard.clear_ready();
|
||||||
Poll::Pending
|
Poll::Pending
|
||||||
}
|
}
|
||||||
Err(err) => Poll::Ready(Err(err)),
|
Err(err) => Poll::Ready(Err(err)),
|
||||||
@ -128,7 +98,6 @@ impl IntoRawFd for PolledFd {
|
|||||||
// its driver
|
// its driver
|
||||||
self.fd
|
self.fd
|
||||||
.into_inner()
|
.into_inner()
|
||||||
.expect("failed to remove polled file descriptor from reactor")
|
|
||||||
.into_raw_fd()
|
.into_raw_fd()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut rt = tokio::runtime::Runtime::new().expect("failed to spawn tokio runtime");
|
let rt = tokio::runtime::Runtime::new().expect("failed to spawn tokio runtime");
|
||||||
|
|
||||||
if let Err(err) = rt.block_on(do_main(use_sd_notify, path)) {
|
if let Err(err) = rt.block_on(do_main(use_sd_notify, path)) {
|
||||||
eprintln!("error: {}", err);
|
eprintln!("error: {}", err);
|
||||||
|
Loading…
Reference in New Issue
Block a user