From 269b6a97ff00913322134ddbc7d47ee2796659ae Mon Sep 17 00:00:00 2001 From: Frank Rehwinkel Date: Fri, 21 Oct 2022 12:23:20 -0400 Subject: [PATCH] simplify driver operation futures These functions being unnecessary is probably the result of the recent introduction of the Completable trait. By definition, all the specific work to create a driver operation's results given the cqe data is done by the complete function now. --- src/driver/read.rs | 14 -------------- src/driver/readv.rs | 14 -------------- src/driver/recv_from.rs | 19 ------------------- src/driver/send_to.rs | 15 --------------- src/driver/socket.rs | 8 ++++---- src/driver/write.rs | 19 +------------------ src/driver/writev.rs | 19 +------------------ src/fs/file.rs | 8 ++++---- 8 files changed, 10 insertions(+), 106 deletions(-) diff --git a/src/driver/read.rs b/src/driver/read.rs index 9ee93734..ecdc3e4b 100644 --- a/src/driver/read.rs +++ b/src/driver/read.rs @@ -4,7 +4,6 @@ use crate::BufResult; use crate::driver::op::Completable; use std::io; -use std::task::{Context, Poll}; pub(crate) struct Read { /// Holds a strong ref to the FD, preventing the file from being closed @@ -35,19 +34,6 @@ impl Op> { }, ) } - - pub(crate) async fn read(mut self) -> BufResult { - crate::future::poll_fn(move |cx| self.poll_read(cx)).await - } - - pub(crate) fn poll_read(&mut self, cx: &mut Context<'_>) -> Poll> { - use std::future::Future; - use std::pin::Pin; - - let complete = ready!(Pin::new(self).poll(cx)); - - Poll::Ready(complete) - } } impl Completable for Read diff --git a/src/driver/readv.rs b/src/driver/readv.rs index 60b26a04..118b5936 100644 --- a/src/driver/readv.rs +++ b/src/driver/readv.rs @@ -5,7 +5,6 @@ use crate::BufResult; use crate::driver::op::Completable; use libc::iovec; use std::io; -use std::task::{Context, Poll}; pub(crate) struct Readv { /// Holds a strong ref to the FD, preventing the file from being closed @@ -54,19 +53,6 @@ impl Op> { }, ) } - - pub(crate) async fn readv(mut self) -> BufResult> { - crate::future::poll_fn(move |cx| self.poll_readv(cx)).await - } - - pub(crate) fn poll_readv(&mut self, cx: &mut Context<'_>) -> Poll>> { - use std::future::Future; - use std::pin::Pin; - - let complete = ready!(Pin::new(self).poll(cx)); - - Poll::Ready(complete) - } } impl Completable for Readv diff --git a/src/driver/recv_from.rs b/src/driver/recv_from.rs index 7fba7a20..2fd81b48 100644 --- a/src/driver/recv_from.rs +++ b/src/driver/recv_from.rs @@ -7,7 +7,6 @@ use crate::{ use socket2::SockAddr; use std::{ io::IoSliceMut, - task::{Context, Poll}, {boxed::Box, io, net::SocketAddr}, }; @@ -53,24 +52,6 @@ impl Op> { }, ) } - - pub(crate) async fn recv(mut self) -> BufResult<(usize, SocketAddr), T> { - use crate::future::poll_fn; - - poll_fn(move |cx| self.poll_recv_from(cx)).await - } - - pub(crate) fn poll_recv_from( - &mut self, - cx: &mut Context<'_>, - ) -> Poll> { - use std::future::Future; - use std::pin::Pin; - - let complete = ready!(Pin::new(self).poll(cx)); - - Poll::Ready(complete) - } } impl Completable for RecvFrom diff --git a/src/driver/send_to.rs b/src/driver/send_to.rs index 9e62b53a..82dfe78c 100644 --- a/src/driver/send_to.rs +++ b/src/driver/send_to.rs @@ -4,7 +4,6 @@ use crate::driver::{Op, SharedFd}; use crate::BufResult; use socket2::SockAddr; use std::io::IoSlice; -use std::task::{Context, Poll}; use std::{boxed::Box, io, net::SocketAddr}; pub(crate) struct SendTo { @@ -55,20 +54,6 @@ impl Op> { }, ) } - - pub(crate) async fn send(mut self) -> BufResult { - use crate::future::poll_fn; - - poll_fn(move |cx| self.poll_send(cx)).await - } - - pub(crate) fn poll_send(&mut self, cx: &mut Context<'_>) -> Poll> { - use std::future::Future; - use std::pin::Pin; - - let complete = ready!(Pin::new(self).poll(cx)); - Poll::Ready(complete) - } } impl Completable for SendTo diff --git a/src/driver/socket.rs b/src/driver/socket.rs index 2419551e..cbfdff60 100644 --- a/src/driver/socket.rs +++ b/src/driver/socket.rs @@ -41,7 +41,7 @@ impl Socket { pub(crate) async fn write(&self, buf: T) -> crate::BufResult { let op = Op::write_at(&self.fd, buf, 0).unwrap(); - op.write().await + op.await } pub(crate) async fn send_to( @@ -50,12 +50,12 @@ impl Socket { socket_addr: SocketAddr, ) -> crate::BufResult { let op = Op::send_to(&self.fd, buf, socket_addr).unwrap(); - op.send().await + op.await } pub(crate) async fn read(&self, buf: T) -> crate::BufResult { let op = Op::read_at(&self.fd, buf, 0).unwrap(); - op.read().await + op.await } pub(crate) async fn recv_from( @@ -63,7 +63,7 @@ impl Socket { buf: T, ) -> crate::BufResult<(usize, SocketAddr), T> { let op = Op::recv_from(&self.fd, buf).unwrap(); - op.recv().await + op.await } pub(crate) async fn accept(&self) -> io::Result<(Socket, Option)> { diff --git a/src/driver/write.rs b/src/driver/write.rs index 648cda17..38b08a05 100644 --- a/src/driver/write.rs +++ b/src/driver/write.rs @@ -4,10 +4,7 @@ use crate::{ driver::{Op, SharedFd}, BufResult, }; -use std::{ - io, - task::{Context, Poll}, -}; +use std::io; pub(crate) struct Write { /// Holds a strong ref to the FD, preventing the file from being closed @@ -38,20 +35,6 @@ impl Op> { }, ) } - - pub(crate) async fn write(mut self) -> BufResult { - use crate::future::poll_fn; - - poll_fn(move |cx| self.poll_write(cx)).await - } - - pub(crate) fn poll_write(&mut self, cx: &mut Context<'_>) -> Poll> { - use std::future::Future; - use std::pin::Pin; - - let complete = ready!(Pin::new(self).poll(cx)); - Poll::Ready(complete) - } } impl Completable for Write diff --git a/src/driver/writev.rs b/src/driver/writev.rs index 3d064e7d..c9018093 100644 --- a/src/driver/writev.rs +++ b/src/driver/writev.rs @@ -5,10 +5,7 @@ use crate::{ BufResult, }; use libc::iovec; -use std::{ - io, - task::{Context, Poll}, -}; +use std::io; pub(crate) struct Writev { /// Holds a strong ref to the FD, preventing the file from being closed @@ -56,20 +53,6 @@ impl Op> { }, ) } - - pub(crate) async fn writev(mut self) -> BufResult> { - use crate::future::poll_fn; - - poll_fn(move |cx| self.poll_writev(cx)).await - } - - pub(crate) fn poll_writev(&mut self, cx: &mut Context<'_>) -> Poll>> { - use std::future::Future; - use std::pin::Pin; - - let complete = ready!(Pin::new(self).poll(cx)); - Poll::Ready(complete) - } } impl Completable for Writev diff --git a/src/fs/file.rs b/src/fs/file.rs index d3ec027e..5d938a50 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -176,7 +176,7 @@ impl File { pub async fn read_at(&self, buf: T, pos: u64) -> crate::BufResult { // Submit the read operation let op = Op::read_at(&self.fd, buf, pos).unwrap(); - op.read().await + op.await } /// Read some bytes at the specified offset from the file into the specified @@ -231,7 +231,7 @@ impl File { ) -> crate::BufResult> { // Submit the read operation let op = Op::readv_at(&self.fd, bufs, pos).unwrap(); - op.readv().await + op.await } /// Write data from buffers into this file at the specified offset, @@ -287,7 +287,7 @@ impl File { pos: u64, ) -> crate::BufResult> { let op = Op::writev_at(&self.fd, buf, pos).unwrap(); - op.writev().await + op.await } /// Write a buffer into this file at the specified offset, returning how @@ -338,7 +338,7 @@ impl File { /// [`Ok(n)`]: Ok pub async fn write_at(&self, buf: T, pos: u64) -> crate::BufResult { let op = Op::write_at(&self.fd, buf, pos).unwrap(); - op.write().await + op.await } /// Attempts to sync all OS-internal metadata to disk.