From 4b48324dc9773af36ea96219059989131c8f0666 Mon Sep 17 00:00:00 2001 From: ssrlive <30760636+ssrlive@users.noreply.github.com> Date: Fri, 19 Jan 2024 20:39:34 +0800 Subject: [PATCH] rename to unix_device --- src/async/mod.rs | 4 ++-- src/async/{device.rs => unix_device.rs} | 16 +++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) rename src/async/{device.rs => unix_device.rs} (93%) diff --git a/src/async/mod.rs b/src/async/mod.rs index 4e7eb402..e816ad7a 100644 --- a/src/async/mod.rs +++ b/src/async/mod.rs @@ -20,9 +20,9 @@ use crate::configuration::Configuration; use crate::platform::create; #[cfg(unix)] -mod device; +mod unix_device; #[cfg(unix)] -pub use self::device::AsyncDevice; +pub use unix_device::AsyncDevice; #[cfg(target_os = "windows")] mod win_device; diff --git a/src/async/device.rs b/src/async/unix_device.rs similarity index 93% rename from src/async/device.rs rename to src/async/unix_device.rs index a7bf9f71..e334ea83 100644 --- a/src/async/device.rs +++ b/src/async/unix_device.rs @@ -12,12 +12,10 @@ // // 0. You just DO WHAT THE FUCK YOU WANT TO. -use std::io; -use std::io::{IoSlice, Read, Write}; - use core::pin::Pin; use core::task::{Context, Poll}; use futures_core::ready; +use std::io::{IoSlice, Read, Write}; use tokio::io::unix::AsyncFd; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; use tokio_util::codec::Framed; @@ -33,7 +31,7 @@ pub struct AsyncDevice { impl AsyncDevice { /// Create a new `AsyncDevice` wrapping around a `Device`. - pub fn new(device: Device) -> io::Result { + pub fn new(device: Device) -> std::io::Result { device.set_nonblock()?; Ok(AsyncDevice { inner: AsyncFd::new(device)?, @@ -64,7 +62,7 @@ impl AsyncRead for AsyncDevice { mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf, - ) -> Poll> { + ) -> Poll> { loop { let mut guard = ready!(self.inner.poll_read_ready_mut(cx))?; let rbuf = buf.initialize_unfilled(); @@ -81,7 +79,7 @@ impl AsyncWrite for AsyncDevice { mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], - ) -> Poll> { + ) -> Poll> { loop { let mut guard = ready!(self.inner.poll_write_ready_mut(cx))?; match guard.try_io(|inner| inner.get_mut().write(buf)) { @@ -91,7 +89,7 @@ impl AsyncWrite for AsyncDevice { } } - fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { loop { let mut guard = ready!(self.inner.poll_write_ready_mut(cx))?; match guard.try_io(|inner| inner.get_mut().flush()) { @@ -101,7 +99,7 @@ impl AsyncWrite for AsyncDevice { } } - fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll> { + fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) } @@ -109,7 +107,7 @@ impl AsyncWrite for AsyncDevice { mut self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], - ) -> Poll> { + ) -> Poll> { loop { let mut guard = ready!(self.inner.poll_write_ready_mut(cx))?; match guard.try_io(|inner| inner.get_mut().write_vectored(bufs)) {