fix async-std

This commit is contained in:
Christien Rioux 2024-11-06 18:39:38 -05:00
parent 547427271c
commit 99bc2aaa5f
4 changed files with 10 additions and 10 deletions

View File

@ -17,6 +17,8 @@ path = "src/main.rs"
[features]
default = ["rt-tokio"]
default-async-std = ["rt-async-std"]
rt-async-std = [
"async-std",
"veilid-tools/rt-async-std",

View File

@ -8,12 +8,10 @@ use core::str::FromStr;
cfg_if! {
if #[cfg(feature="rt-async-std")] {
pub use async_std::net::TcpStream;
pub fn block_on<F: Future<Output = T>, T>(f: F) -> T {
async_std::task::block_on(f)
}
} else if #[cfg(feature="rt-tokio")] {
pub use tokio::net::TcpStream;
pub fn block_on<F: Future<Output = T>, T>(f: F) -> T {
let rt = tokio::runtime::Runtime::new().unwrap();
let local = tokio::task::LocalSet::new();

View File

@ -119,11 +119,9 @@ pub fn set_tcp_stream_linger(
cfg_if! {
if #[cfg(feature="rt-async-std")] {
pub type IncomingStream = Incoming;
pub type ReadHalf = futures_util::io::ReadHalf<TcpStream>,
pub type WriteHalf = futures_util::io::WriteHalf<TcpStream>,
pub type ReadHalf = futures_util::io::ReadHalf<TcpStream>;
pub type WriteHalf = futures_util::io::WriteHalf<TcpStream>;
} else if #[cfg(feature="rt-tokio")] {
pub type IncomingStream = tokio_stream::wrappers::TcpListenerStream;
pub type ReadHalf = tokio::net::tcp::OwnedReadHalf;
pub type WriteHalf = tokio::net::tcp::OwnedWriteHalf;
} else {
@ -131,12 +129,14 @@ cfg_if! {
}
}
pub fn async_tcp_listener_incoming(tcp_listener: TcpListener) -> IncomingStream {
pub fn async_tcp_listener_incoming(
tcp_listener: TcpListener,
) -> Pin<Box<impl futures_util::stream::Stream<Item = std::io::Result<TcpStream>> + Send>> {
cfg_if! {
if #[cfg(feature="rt-async-std")] {
tcp_listener.incoming()
Box::pin(tcp_listener.into_incoming())
} else if #[cfg(feature="rt-tokio")] {
tokio_stream::wrappers::TcpListenerStream::new(tcp_listener)
Box::pin(tokio_stream::wrappers::TcpListenerStream::new(tcp_listener))
} else {
compile_error!("needs executor implementation");
}

View File

@ -205,7 +205,7 @@ impl RouterClient {
ts_writer = writer.compat_write();
} else if #[cfg(feature="rt-async-std")] {
use futures_util::io::AsyncReadExt;
ts = ::async_std::net::TcpStream::connect(addrs.as_slice()).await?;
let ts = ::async_std::net::TcpStream::connect(addrs.as_slice()).await?;
(ts_reader, ts_writer) = ts.split();
} else {
compile_error!("must choose an executor");