mirror of
https://gitlab.com/veilid/veilid.git
synced 2025-03-30 17:48:03 -04:00
fix async-std
This commit is contained in:
parent
547427271c
commit
99bc2aaa5f
@ -17,6 +17,8 @@ path = "src/main.rs"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["rt-tokio"]
|
default = ["rt-tokio"]
|
||||||
|
default-async-std = ["rt-async-std"]
|
||||||
|
|
||||||
rt-async-std = [
|
rt-async-std = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"veilid-tools/rt-async-std",
|
"veilid-tools/rt-async-std",
|
||||||
|
@ -8,12 +8,10 @@ use core::str::FromStr;
|
|||||||
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(feature="rt-async-std")] {
|
if #[cfg(feature="rt-async-std")] {
|
||||||
pub use async_std::net::TcpStream;
|
|
||||||
pub fn block_on<F: Future<Output = T>, T>(f: F) -> T {
|
pub fn block_on<F: Future<Output = T>, T>(f: F) -> T {
|
||||||
async_std::task::block_on(f)
|
async_std::task::block_on(f)
|
||||||
}
|
}
|
||||||
} else if #[cfg(feature="rt-tokio")] {
|
} else if #[cfg(feature="rt-tokio")] {
|
||||||
pub use tokio::net::TcpStream;
|
|
||||||
pub fn block_on<F: Future<Output = T>, T>(f: F) -> T {
|
pub fn block_on<F: Future<Output = T>, T>(f: F) -> T {
|
||||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
let local = tokio::task::LocalSet::new();
|
let local = tokio::task::LocalSet::new();
|
||||||
|
@ -119,11 +119,9 @@ pub fn set_tcp_stream_linger(
|
|||||||
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(feature="rt-async-std")] {
|
if #[cfg(feature="rt-async-std")] {
|
||||||
pub type IncomingStream = Incoming;
|
pub type ReadHalf = futures_util::io::ReadHalf<TcpStream>;
|
||||||
pub type ReadHalf = futures_util::io::ReadHalf<TcpStream>,
|
pub type WriteHalf = futures_util::io::WriteHalf<TcpStream>;
|
||||||
pub type WriteHalf = futures_util::io::WriteHalf<TcpStream>,
|
|
||||||
} else if #[cfg(feature="rt-tokio")] {
|
} else if #[cfg(feature="rt-tokio")] {
|
||||||
pub type IncomingStream = tokio_stream::wrappers::TcpListenerStream;
|
|
||||||
pub type ReadHalf = tokio::net::tcp::OwnedReadHalf;
|
pub type ReadHalf = tokio::net::tcp::OwnedReadHalf;
|
||||||
pub type WriteHalf = tokio::net::tcp::OwnedWriteHalf;
|
pub type WriteHalf = tokio::net::tcp::OwnedWriteHalf;
|
||||||
} else {
|
} 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! {
|
cfg_if! {
|
||||||
if #[cfg(feature="rt-async-std")] {
|
if #[cfg(feature="rt-async-std")] {
|
||||||
tcp_listener.incoming()
|
Box::pin(tcp_listener.into_incoming())
|
||||||
} else if #[cfg(feature="rt-tokio")] {
|
} else if #[cfg(feature="rt-tokio")] {
|
||||||
tokio_stream::wrappers::TcpListenerStream::new(tcp_listener)
|
Box::pin(tokio_stream::wrappers::TcpListenerStream::new(tcp_listener))
|
||||||
} else {
|
} else {
|
||||||
compile_error!("needs executor implementation");
|
compile_error!("needs executor implementation");
|
||||||
}
|
}
|
||||||
|
@ -205,7 +205,7 @@ impl RouterClient {
|
|||||||
ts_writer = writer.compat_write();
|
ts_writer = writer.compat_write();
|
||||||
} else if #[cfg(feature="rt-async-std")] {
|
} else if #[cfg(feature="rt-async-std")] {
|
||||||
use futures_util::io::AsyncReadExt;
|
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();
|
(ts_reader, ts_writer) = ts.split();
|
||||||
} else {
|
} else {
|
||||||
compile_error!("must choose an executor");
|
compile_error!("must choose an executor");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user