Remove direct rustix dep
This commit is contained in:
parent
347b9ba83a
commit
53ef4552f6
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -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",
|
||||
]
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -14,14 +14,14 @@ async fn echo_to(port: u16) -> Result<(), Box<dyn std::error::Error>> {
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
42
src/io.rs
42
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<rustix::io::Result<Arc<TcpListenerBuilder>>>,
|
||||
io: Option<Result<Arc<TcpListenerBuilder>>>,
|
||||
}
|
||||
|
||||
struct Connect {
|
||||
io: Option<rustix::io::Result<Arc<TcpStreamBuilder>>>,
|
||||
io: Option<Result<Arc<TcpStreamBuilder>>>,
|
||||
}
|
||||
|
||||
impl<T: AsFd + 'static> Drop for Async<T> {
|
||||
|
@ -62,7 +62,7 @@ impl<T: AsFd + 'static> Drop for Async<T> {
|
|||
}
|
||||
|
||||
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 {
|
||||
io: Some(polldance::net::TcpListener::bind(ip, port).map(Arc::new)),
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ impl Async<TcpListener> {
|
|||
.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?;
|
||||
|
||||
Ok((Async::new(stream), addr))
|
||||
|
@ -78,7 +78,7 @@ impl Async<TcpListener> {
|
|||
}
|
||||
|
||||
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 {
|
||||
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) }
|
||||
}
|
||||
|
||||
pub async fn ready(&self, interests: Readiness) -> rustix::io::Result<Readiness> {
|
||||
pub async fn ready(&self, interests: Readiness) -> Result<Readiness> {
|
||||
Ready {
|
||||
io: &self.io,
|
||||
interests,
|
||||
|
@ -100,7 +100,7 @@ impl<T: AsFd + 'static> Async<T> {
|
|||
.await
|
||||
}
|
||||
|
||||
pub async fn read(&self, bytes: &mut [u8]) -> rustix::io::Result<ReadBytes> {
|
||||
pub async fn read(&self, bytes: &mut [u8]) -> Result<ReadBytes> {
|
||||
Read {
|
||||
io: &self.io,
|
||||
bytes,
|
||||
|
@ -108,11 +108,11 @@ impl<T: AsFd + 'static> Async<T> {
|
|||
.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)
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
while start < bytes.len() {
|
||||
|
@ -125,7 +125,7 @@ impl<T: AsFd + 'static> Async<T> {
|
|||
Ok(start)
|
||||
}
|
||||
|
||||
pub async fn write(&self, bytes: &[u8]) -> rustix::io::Result<usize> {
|
||||
pub async fn write(&self, bytes: &[u8]) -> Result<usize> {
|
||||
Write {
|
||||
io: &self.io,
|
||||
bytes,
|
||||
|
@ -133,11 +133,11 @@ impl<T: AsFd + 'static> Async<T> {
|
|||
.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)
|
||||
}
|
||||
|
||||
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<T: AsFd + 'static> Async<T> {
|
|||
}
|
||||
|
||||
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> {
|
||||
let mut this = self.as_mut();
|
||||
|
@ -186,7 +186,7 @@ impl Future for Bind {
|
|||
}
|
||||
|
||||
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> {
|
||||
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<ReadBytes>;
|
||||
type Output = Result<ReadBytes>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
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<usize>;
|
||||
type Output = Result<usize>;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
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<Self::Output> {
|
||||
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<Readiness>;
|
||||
type Output = Result<Readiness>;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let interests = self.interests | Readiness::hangup();
|
||||
|
|
|
@ -13,5 +13,5 @@ pub fn block_on<F: Future>(future: F) -> Result<F::Output, Error> {
|
|||
}
|
||||
|
||||
pub mod net {
|
||||
pub use polldance::net::{TcpListener, TcpStream};
|
||||
pub use polldance::net::{SocketAddrAny, SocketAddrUnix, TcpListener, TcpStream};
|
||||
}
|
||||
|
|
|
@ -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<rustix::io::Error> for Error {
|
||||
fn from(e: rustix::io::Error) -> Self {
|
||||
impl From<polldance::io::Error> for Error {
|
||||
fn from(e: polldance::io::Error) -> Self {
|
||||
Error::IO(e)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue