Skip to content

Commit 4a32642

Browse files
committed
tokio: fix windows build
1 parent 6c5bf68 commit 4a32642

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ tokio = ["dep:tokio", "dep:tokio-stream"]
2121

2222
[dependencies]
2323
async-trait = "^0.1.89"
24+
cfg-if = "^1.0"
2425
futures-core = "^0.3"
2526
futures-io = "^0.3"
2627

src/implementors/tokio.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use crate::{AsyncIOHandle, Executor, IOHandle, Reactor, Runtime, RuntimeKit, Task, sys::IO};
44
use async_trait::async_trait;
5+
use cfg_if::cfg_if;
56
use futures_core::Stream;
67
use std::{
78
future::Future,
@@ -11,7 +12,7 @@ use std::{
1112
task::{Context, Poll},
1213
time::{Duration, Instant},
1314
};
14-
use tokio::{io::unix::AsyncFd, net::TcpStream, runtime::Handle};
15+
use tokio::{net::TcpStream, runtime::Handle};
1516
use tokio_stream::{StreamExt, wrappers::IntervalStream};
1617
use tokio_util::compat::TokioAsyncReadCompatExt;
1718

@@ -117,12 +118,16 @@ impl Reactor for Tokio {
117118
socket: IOHandle<H>,
118119
) -> io::Result<impl AsyncIOHandle + Send> {
119120
let _enter = self.handle().as_ref().map(|handle| handle.enter());
120-
if cfg!(unix) {
121-
Ok(Box::new(unix::AsyncFdWrapper(AsyncFd::new(socket)?)))
122-
} else {
123-
Err(io::Error::other(
124-
"Registering FD on tokio reactor is only supported on unix",
125-
))
121+
cfg_if! {
122+
if #[cfg(unix)] {
123+
Ok(Box::new(unix::AsyncFdWrapper(
124+
tokio::io::unix::AsyncFd::new(socket)?,
125+
)))
126+
} else {
127+
Err::<&[u8], _>(io::Error::other(
128+
"Registering FD on tokio reactor is only supported on unix",
129+
))
130+
}
126131
}
127132
}
128133

@@ -149,6 +154,7 @@ mod unix {
149154
use super::*;
150155
use futures_io::{AsyncRead, AsyncWrite};
151156
use std::io::{IoSlice, IoSliceMut, Read, Write};
157+
use tokio::io::unix::AsyncFd;
152158

153159
pub(super) struct AsyncFdWrapper<H: IO + Send + 'static>(pub(super) AsyncFd<IOHandle<H>>);
154160

0 commit comments

Comments
 (0)