22
33use crate :: { AsyncIOHandle , Executor , IOHandle , Reactor , Runtime , RuntimeKit , Task , sys:: IO } ;
44use async_trait:: async_trait;
5+ use cfg_if:: cfg_if;
56use futures_core:: Stream ;
67use 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 } ;
1516use tokio_stream:: { StreamExt , wrappers:: IntervalStream } ;
1617use 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 :: <windows:: Dummy , _>( 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
@@ -260,6 +266,42 @@ mod unix {
260266 }
261267}
262268
269+ #[ cfg( windows) ]
270+ mod windows {
271+ use super :: * ;
272+ use futures_io:: { AsyncRead , AsyncWrite } ;
273+
274+ struct Dummy ;
275+
276+ impl AsyncRead for Dummy {
277+ fn poll_read (
278+ self : Pin < & mut Self > ,
279+ cx : & mut Context < ' _ > ,
280+ buf : & mut [ u8 ] ,
281+ ) -> Poll < io:: Result < usize > > {
282+ Poll :: Pending
283+ }
284+ }
285+
286+ impl AsyncWrite for Dummy {
287+ fn poll_write (
288+ self : Pin < & mut Self > ,
289+ cx : & mut Context < ' _ > ,
290+ buf : & [ u8 ] ,
291+ ) -> Poll < io:: Result < usize > > {
292+ Poll :: Pending
293+ }
294+
295+ fn poll_flush ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
296+ Poll :: Pending
297+ }
298+
299+ fn poll_close ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
300+ Poll :: Pending
301+ }
302+ }
303+ }
304+
263305#[ cfg( test) ]
264306mod tests {
265307 use super :: * ;
0 commit comments