From 53ef4552f69fddb71d8ccb65b5e1ed54e74fe154 Mon Sep 17 00:00:00 2001 From: "Aode (lion)" Date: Wed, 16 Feb 2022 11:58:58 -0500 Subject: [PATCH] Remove direct rustix dep --- Cargo.lock | 3 +-- Cargo.toml | 1 - examples/async-echo.rs | 4 ++-- src/io.rs | 42 +++++++++++++++++++++--------------------- src/lib.rs | 2 +- src/reactor.rs | 9 ++++----- 6 files changed, 29 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 82cc0d3..ed3321a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,7 +46,6 @@ version = "0.1.0" dependencies = [ "async-join", "polldance", - "rustix", ] [[package]] @@ -70,7 +69,7 @@ checksum = "5bdc16c6ce4c85d9b46b4e66f2a814be5b3f034dbd5131c268a24ca26d970db8" [[package]] name = "polldance" version = "0.1.0" -source = "git+https://git.asonix.dog/safe-async/polldance#ae196a2ecf1c92036b07ff9f5288bc135fa7f6e9" +source = "git+https://git.asonix.dog/safe-async/polldance#fc3bdc92c53625487af776b7edd1a1b7f4bc587b" dependencies = [ "rustix", ] diff --git a/Cargo.toml b/Cargo.toml index 6e1a6ec..c96979e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" [dependencies] polldance = { git = "https://git.asonix.dog/safe-async/polldance" } -rustix = "0.33.2" [dev-dependencies] async-join = { git = "https://git.asonix.dog/safe-async/async-join" } diff --git a/examples/async-echo.rs b/examples/async-echo.rs index ccee8cd..5f2969b 100644 --- a/examples/async-echo.rs +++ b/examples/async-echo.rs @@ -14,14 +14,14 @@ async fn echo_to(port: u16) -> Result<(), Box> { loop { let mut buf = [0; 1024]; if let Err(e) = stream.read(&mut buf).await { - if e == rustix::io::Error::PIPE { + if e == foxtrot::io::Error::PIPE { break; } return Err(e.into()); } if let Err(e) = stream.write_all(&buf).await { - if e == rustix::io::Error::PIPE { + if e == foxtrot::io::Error::PIPE { break; } diff --git a/src/io.rs b/src/io.rs index b968581..4514c1e 100644 --- a/src/io.rs +++ b/src/io.rs @@ -1,6 +1,5 @@ use crate::reactor::ReactorRef; use polldance::net::{TcpListener, TcpListenerBuilder, TcpStream, TcpStreamBuilder}; -use rustix::{fd::AsFd, net::SocketAddrAny}; use std::{ future::Future, net::IpAddr, @@ -10,8 +9,9 @@ use std::{ }; pub use polldance::{ - io::{Nonblocking, ReadBytes}, - Readiness, + io::{Error, Nonblocking, ReadBytes, Result}, + net::SocketAddrAny, + AsFd, Readiness, }; macro_rules! poll_nonblocking { @@ -48,11 +48,11 @@ struct Accept<'a> { } struct Bind { - io: Option>>, + io: Option>>, } struct Connect { - io: Option>>, + io: Option>>, } impl Drop for Async { @@ -62,7 +62,7 @@ impl Drop for Async { } impl Async { - pub async fn bind(ip: IpAddr, port: u16) -> rustix::io::Result> { + pub async fn bind(ip: IpAddr, port: u16) -> Result> { Bind { io: Some(polldance::net::TcpListener::bind(ip, port).map(Arc::new)), } @@ -70,7 +70,7 @@ impl Async { .map(Async::new) } - pub async fn accept(&self) -> rustix::io::Result<(Async, SocketAddrAny)> { + pub async fn accept(&self) -> Result<(Async, SocketAddrAny)> { let (stream, addr) = Accept { io: &self.io }.await?; Ok((Async::new(stream), addr)) @@ -78,7 +78,7 @@ impl Async { } impl Async { - pub async fn connect(ip: IpAddr, port: u16) -> rustix::io::Result> { + pub async fn connect(ip: IpAddr, port: u16) -> Result> { Connect { io: Some(polldance::net::TcpStream::connect(ip, port).map(Arc::new)), } @@ -92,7 +92,7 @@ impl Async { Async { io: Arc::new(io) } } - pub async fn ready(&self, interests: Readiness) -> rustix::io::Result { + pub async fn ready(&self, interests: Readiness) -> Result { Ready { io: &self.io, interests, @@ -100,7 +100,7 @@ impl Async { .await } - pub async fn read(&self, bytes: &mut [u8]) -> rustix::io::Result { + pub async fn read(&self, bytes: &mut [u8]) -> Result { Read { io: &self.io, bytes, @@ -108,11 +108,11 @@ impl Async { .await } - pub fn read_nonblocking(&self, buf: &mut [u8]) -> rustix::io::Result> { + pub fn read_nonblocking(&self, buf: &mut [u8]) -> Result> { polldance::io::try_read(self.io.as_ref(), buf) } - pub async fn read_exact(&self, bytes: &mut [u8]) -> rustix::io::Result { + pub async fn read_exact(&self, bytes: &mut [u8]) -> Result { let mut start = 0; while start < bytes.len() { @@ -125,7 +125,7 @@ impl Async { Ok(start) } - pub async fn write(&self, bytes: &[u8]) -> rustix::io::Result { + pub async fn write(&self, bytes: &[u8]) -> Result { Write { io: &self.io, bytes, @@ -133,11 +133,11 @@ impl Async { .await } - pub fn write_nonblocking(&self, buf: &[u8]) -> rustix::io::Result> { + pub fn write_nonblocking(&self, buf: &[u8]) -> Result> { polldance::io::try_write(self.io.as_ref(), buf) } - pub async fn write_all(&self, bytes: &[u8]) -> rustix::io::Result<()> { + pub async fn write_all(&self, bytes: &[u8]) -> Result<()> { let mut start = 0; while start < bytes.len() { @@ -149,7 +149,7 @@ impl Async { } impl Future for Bind { - type Output = rustix::io::Result; + type Output = Result; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let mut this = self.as_mut(); @@ -186,7 +186,7 @@ impl Future for Bind { } impl Future for Connect { - type Output = rustix::io::Result; + type Output = Result; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let mut this = self.as_mut(); @@ -227,7 +227,7 @@ impl<'a, T> Future for Read<'a, T> where T: AsFd + 'static, { - type Output = rustix::io::Result; + type Output = Result; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let mut this = self.as_mut(); @@ -251,7 +251,7 @@ impl<'a, T> Future for Write<'a, T> where T: AsFd + 'static, { - type Output = rustix::io::Result; + type Output = Result; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { poll_nonblocking!(polldance::io::try_write(self.io.as_ref(), self.bytes)); @@ -270,7 +270,7 @@ where } impl<'a> Future for Accept<'a> { - type Output = rustix::io::Result<(TcpStream, SocketAddrAny)>; + type Output = Result<(TcpStream, SocketAddrAny)>; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { poll_nonblocking!(self.io.try_accept()); @@ -292,7 +292,7 @@ impl<'a, T> Future for Ready<'a, T> where T: AsFd + 'static, { - type Output = rustix::io::Result; + type Output = Result; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let interests = self.interests | Readiness::hangup(); diff --git a/src/lib.rs b/src/lib.rs index 9c9a91b..e4fc4d4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,5 +13,5 @@ pub fn block_on(future: F) -> Result { } pub mod net { - pub use polldance::net::{TcpListener, TcpStream}; + pub use polldance::net::{SocketAddrAny, SocketAddrUnix, TcpListener, TcpStream}; } diff --git a/src/reactor.rs b/src/reactor.rs index db874b5..d84e802 100644 --- a/src/reactor.rs +++ b/src/reactor.rs @@ -1,5 +1,4 @@ -use polldance::{Key, NotifyToken, PollManager, Readiness}; -use rustix::fd::AsFd; +use polldance::{AsFd, Key, NotifyToken, PollManager, Readiness}; use std::{ collections::{BTreeMap, HashMap}, future::Future, @@ -17,7 +16,7 @@ thread_local! { #[derive(Debug)] pub enum Error { - IO(rustix::io::Error), + IO(polldance::io::Error), AlreadyInitialized, Uninitialized, } @@ -109,8 +108,8 @@ impl ReactorRef<'_> { } } -impl From for Error { - fn from(e: rustix::io::Error) -> Self { +impl From for Error { + fn from(e: polldance::io::Error) -> Self { Error::IO(e) } }