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,41 @@ mod unix {
260266 }
261267}
262268
269+ #[ cfg( windows) ]
270+ mod windows {
271+ use super :: * ;
272+
273+ struct Dummy ;
274+
275+ impl AsyncRead for Dummy {
276+ fn poll_read (
277+ self : Pin < & mut Self > ,
278+ cx : & mut Context < ' _ > ,
279+ buf : & mut [ u8 ] ,
280+ ) -> Poll < Result < usize > > {
281+ Poll :: Pending
282+ }
283+ }
284+
285+ impl AsyncWrite for Dummy {
286+ fn poll_write (
287+ self : Pin < & mut Self > ,
288+ cx : & mut Context < ' _ > ,
289+ buf : & [ u8 ] ,
290+ ) -> Poll < Result < usize > > {
291+ Poll :: Pending
292+ }
293+
294+ fn poll_flush ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) > > {
295+ Poll :: Pending
296+ }
297+
298+ fn poll_close ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) > > {
299+ Poll :: Pending
300+ }
301+ }
302+ }
303+
263304#[ cfg( test) ]
264305mod tests {
265306 use super :: * ;
0 commit comments