Remove direct rustix dep

This commit is contained in:
Aode (lion) 2022-02-16 11:58:58 -05:00
parent 347b9ba83a
commit 53ef4552f6
6 changed files with 29 additions and 32 deletions

3
Cargo.lock generated
View file

@ -46,7 +46,6 @@ version = "0.1.0"
dependencies = [ dependencies = [
"async-join", "async-join",
"polldance", "polldance",
"rustix",
] ]
[[package]] [[package]]
@ -70,7 +69,7 @@ checksum = "5bdc16c6ce4c85d9b46b4e66f2a814be5b3f034dbd5131c268a24ca26d970db8"
[[package]] [[package]]
name = "polldance" name = "polldance"
version = "0.1.0" 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 = [ dependencies = [
"rustix", "rustix",
] ]

View file

@ -7,7 +7,6 @@ edition = "2021"
[dependencies] [dependencies]
polldance = { git = "https://git.asonix.dog/safe-async/polldance" } polldance = { git = "https://git.asonix.dog/safe-async/polldance" }
rustix = "0.33.2"
[dev-dependencies] [dev-dependencies]
async-join = { git = "https://git.asonix.dog/safe-async/async-join" } async-join = { git = "https://git.asonix.dog/safe-async/async-join" }

View file

@ -14,14 +14,14 @@ async fn echo_to(port: u16) -> Result<(), Box<dyn std::error::Error>> {
loop { loop {
let mut buf = [0; 1024]; let mut buf = [0; 1024];
if let Err(e) = stream.read(&mut buf).await { if let Err(e) = stream.read(&mut buf).await {
if e == rustix::io::Error::PIPE { if e == foxtrot::io::Error::PIPE {
break; break;
} }
return Err(e.into()); return Err(e.into());
} }
if let Err(e) = stream.write_all(&buf).await { if let Err(e) = stream.write_all(&buf).await {
if e == rustix::io::Error::PIPE { if e == foxtrot::io::Error::PIPE {
break; break;
} }

View file

@ -1,6 +1,5 @@
use crate::reactor::ReactorRef; use crate::reactor::ReactorRef;
use polldance::net::{TcpListener, TcpListenerBuilder, TcpStream, TcpStreamBuilder}; use polldance::net::{TcpListener, TcpListenerBuilder, TcpStream, TcpStreamBuilder};
use rustix::{fd::AsFd, net::SocketAddrAny};
use std::{ use std::{
future::Future, future::Future,
net::IpAddr, net::IpAddr,
@ -10,8 +9,9 @@ use std::{
}; };
pub use polldance::{ pub use polldance::{
io::{Nonblocking, ReadBytes}, io::{Error, Nonblocking, ReadBytes, Result},
Readiness, net::SocketAddrAny,
AsFd, Readiness,
}; };
macro_rules! poll_nonblocking { macro_rules! poll_nonblocking {
@ -48,11 +48,11 @@ struct Accept<'a> {
} }
struct Bind { struct Bind {
io: Option<rustix::io::Result<Arc<TcpListenerBuilder>>>, io: Option<Result<Arc<TcpListenerBuilder>>>,
} }
struct Connect { struct Connect {
io: Option<rustix::io::Result<Arc<TcpStreamBuilder>>>, io: Option<Result<Arc<TcpStreamBuilder>>>,
} }
impl<T: AsFd + 'static> Drop for Async<T> { impl<T: AsFd + 'static> Drop for Async<T> {
@ -62,7 +62,7 @@ impl<T: AsFd + 'static> Drop for Async<T> {
} }
impl Async<TcpListener> { impl Async<TcpListener> {
pub async fn bind(ip: IpAddr, port: u16) -> rustix::io::Result<Async<TcpListener>> { pub async fn bind(ip: IpAddr, port: u16) -> Result<Async<TcpListener>> {
Bind { Bind {
io: Some(polldance::net::TcpListener::bind(ip, port).map(Arc::new)), io: Some(polldance::net::TcpListener::bind(ip, port).map(Arc::new)),
} }
@ -70,7 +70,7 @@ impl Async<TcpListener> {
.map(Async::new) .map(Async::new)
} }
pub async fn accept(&self) -> rustix::io::Result<(Async<TcpStream>, SocketAddrAny)> { pub async fn accept(&self) -> Result<(Async<TcpStream>, SocketAddrAny)> {
let (stream, addr) = Accept { io: &self.io }.await?; let (stream, addr) = Accept { io: &self.io }.await?;
Ok((Async::new(stream), addr)) Ok((Async::new(stream), addr))
@ -78,7 +78,7 @@ impl Async<TcpListener> {
} }
impl Async<TcpStream> { impl Async<TcpStream> {
pub async fn connect(ip: IpAddr, port: u16) -> rustix::io::Result<Async<TcpStream>> { pub async fn connect(ip: IpAddr, port: u16) -> Result<Async<TcpStream>> {
Connect { Connect {
io: Some(polldance::net::TcpStream::connect(ip, port).map(Arc::new)), io: Some(polldance::net::TcpStream::connect(ip, port).map(Arc::new)),
} }
@ -92,7 +92,7 @@ impl<T: AsFd + 'static> Async<T> {
Async { io: Arc::new(io) } Async { io: Arc::new(io) }
} }
pub async fn ready(&self, interests: Readiness) -> rustix::io::Result<Readiness> { pub async fn ready(&self, interests: Readiness) -> Result<Readiness> {
Ready { Ready {
io: &self.io, io: &self.io,
interests, interests,
@ -100,7 +100,7 @@ impl<T: AsFd + 'static> Async<T> {
.await .await
} }
pub async fn read(&self, bytes: &mut [u8]) -> rustix::io::Result<ReadBytes> { pub async fn read(&self, bytes: &mut [u8]) -> Result<ReadBytes> {
Read { Read {
io: &self.io, io: &self.io,
bytes, bytes,
@ -108,11 +108,11 @@ impl<T: AsFd + 'static> Async<T> {
.await .await
} }
pub fn read_nonblocking(&self, buf: &mut [u8]) -> rustix::io::Result<Nonblocking<ReadBytes>> { pub fn read_nonblocking(&self, buf: &mut [u8]) -> Result<Nonblocking<ReadBytes>> {
polldance::io::try_read(self.io.as_ref(), buf) polldance::io::try_read(self.io.as_ref(), buf)
} }
pub async fn read_exact(&self, bytes: &mut [u8]) -> rustix::io::Result<usize> { pub async fn read_exact(&self, bytes: &mut [u8]) -> Result<usize> {
let mut start = 0; let mut start = 0;
while start < bytes.len() { while start < bytes.len() {
@ -125,7 +125,7 @@ impl<T: AsFd + 'static> Async<T> {
Ok(start) Ok(start)
} }
pub async fn write(&self, bytes: &[u8]) -> rustix::io::Result<usize> { pub async fn write(&self, bytes: &[u8]) -> Result<usize> {
Write { Write {
io: &self.io, io: &self.io,
bytes, bytes,
@ -133,11 +133,11 @@ impl<T: AsFd + 'static> Async<T> {
.await .await
} }
pub fn write_nonblocking(&self, buf: &[u8]) -> rustix::io::Result<Nonblocking<usize>> { pub fn write_nonblocking(&self, buf: &[u8]) -> Result<Nonblocking<usize>> {
polldance::io::try_write(self.io.as_ref(), buf) 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; let mut start = 0;
while start < bytes.len() { while start < bytes.len() {
@ -149,7 +149,7 @@ impl<T: AsFd + 'static> Async<T> {
} }
impl Future for Bind { impl Future for Bind {
type Output = rustix::io::Result<TcpListener>; type Output = Result<TcpListener>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut this = self.as_mut(); let mut this = self.as_mut();
@ -186,7 +186,7 @@ impl Future for Bind {
} }
impl Future for Connect { impl Future for Connect {
type Output = rustix::io::Result<TcpStream>; type Output = Result<TcpStream>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut this = self.as_mut(); let mut this = self.as_mut();
@ -227,7 +227,7 @@ impl<'a, T> Future for Read<'a, T>
where where
T: AsFd + 'static, T: AsFd + 'static,
{ {
type Output = rustix::io::Result<ReadBytes>; type Output = Result<ReadBytes>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut this = self.as_mut(); let mut this = self.as_mut();
@ -251,7 +251,7 @@ impl<'a, T> Future for Write<'a, T>
where where
T: AsFd + 'static, T: AsFd + 'static,
{ {
type Output = rustix::io::Result<usize>; type Output = Result<usize>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
poll_nonblocking!(polldance::io::try_write(self.io.as_ref(), self.bytes)); poll_nonblocking!(polldance::io::try_write(self.io.as_ref(), self.bytes));
@ -270,7 +270,7 @@ where
} }
impl<'a> Future for Accept<'a> { 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<Self::Output> { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
poll_nonblocking!(self.io.try_accept()); poll_nonblocking!(self.io.try_accept());
@ -292,7 +292,7 @@ impl<'a, T> Future for Ready<'a, T>
where where
T: AsFd + 'static, T: AsFd + 'static,
{ {
type Output = rustix::io::Result<Readiness>; type Output = Result<Readiness>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let interests = self.interests | Readiness::hangup(); let interests = self.interests | Readiness::hangup();

View file

@ -13,5 +13,5 @@ pub fn block_on<F: Future>(future: F) -> Result<F::Output, Error> {
} }
pub mod net { pub mod net {
pub use polldance::net::{TcpListener, TcpStream}; pub use polldance::net::{SocketAddrAny, SocketAddrUnix, TcpListener, TcpStream};
} }

View file

@ -1,5 +1,4 @@
use polldance::{Key, NotifyToken, PollManager, Readiness}; use polldance::{AsFd, Key, NotifyToken, PollManager, Readiness};
use rustix::fd::AsFd;
use std::{ use std::{
collections::{BTreeMap, HashMap}, collections::{BTreeMap, HashMap},
future::Future, future::Future,
@ -17,7 +16,7 @@ thread_local! {
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
IO(rustix::io::Error), IO(polldance::io::Error),
AlreadyInitialized, AlreadyInitialized,
Uninitialized, Uninitialized,
} }
@ -109,8 +108,8 @@ impl ReactorRef<'_> {
} }
} }
impl From<rustix::io::Error> for Error { impl From<polldance::io::Error> for Error {
fn from(e: rustix::io::Error) -> Self { fn from(e: polldance::io::Error) -> Self {
Error::IO(e) Error::IO(e)
} }
} }