@@ -12,13 +12,13 @@ use async_io::Async;
1212use std:: collections:: HashMap ;
1313#[ cfg( not( feature = "tokio" ) ) ]
1414use std:: net:: TcpStream ;
15- #[ cfg( unix) ]
16- use std:: os:: unix:: net:: { SocketAddr , UnixStream } ;
15+ #[ cfg( all ( unix, not ( feature = "tokio" ) ) ) ]
16+ use std:: os:: unix:: net:: UnixStream ;
1717#[ cfg( feature = "tokio" ) ]
1818use tokio:: net:: TcpStream ;
1919#[ cfg( feature = "tokio-vsock" ) ]
2020use tokio_vsock:: VsockStream ;
21- #[ cfg( windows) ]
21+ #[ cfg( all ( windows, not ( feature = "tokio" ) ) ) ]
2222use uds_windows:: UnixStream ;
2323#[ cfg( all( feature = "vsock" , not( feature = "tokio" ) ) ) ]
2424use vsock:: VsockStream ;
@@ -55,8 +55,6 @@ pub use ibus::Ibus;
5555#[ path = "vsock.rs" ]
5656// Gotta rename to avoid name conflict with the `vsock` crate.
5757mod vsock_transport;
58- #[ cfg( target_os = "linux" ) ]
59- use std:: os:: linux:: net:: SocketAddrExt ;
6058#[ cfg( any(
6159 all( feature = "vsock" , not( feature = "tokio" ) ) ,
6260 feature = "tokio-vsock"
@@ -102,59 +100,11 @@ impl Transport {
102100 #[ cfg_attr( any( unix, windows) , async_recursion:: async_recursion) ]
103101 pub ( super ) async fn connect ( self ) -> Result < Stream > {
104102 match self {
105- Transport :: Unix ( unix) => {
106- // This is a `path` in case of Windows until uds_windows provides the needed API:
107- // https://github.com/haraldh/rust_uds_windows/issues/14
108- let addr = match unix. take_path ( ) {
109- #[ cfg( unix) ]
110- UnixSocket :: File ( path) => SocketAddr :: from_pathname ( path) ?,
111- #[ cfg( windows) ]
112- UnixSocket :: File ( path) => path,
113- #[ cfg( target_os = "linux" ) ]
114- UnixSocket :: Abstract ( name) => {
115- SocketAddr :: from_abstract_name ( name. as_encoded_bytes ( ) ) ?
116- }
117- UnixSocket :: Dir ( _) | UnixSocket :: TmpDir ( _) => {
118- // You can't connect to a unix:dir.
119- return Err ( Error :: Unsupported ) ;
120- }
121- } ;
122- let stream = crate :: Task :: spawn_blocking (
123- move || -> Result < _ > {
124- #[ cfg( unix) ]
125- let stream = UnixStream :: connect_addr ( & addr) ?;
126- #[ cfg( windows) ]
127- let stream = UnixStream :: connect ( addr) ?;
128- stream. set_nonblocking ( true ) ?;
129-
130- Ok ( stream)
131- } ,
132- "unix stream connection" ,
133- )
134- . await ??;
135- #[ cfg( not( feature = "tokio" ) ) ]
136- {
137- Async :: new ( stream)
138- . map ( Stream :: Unix )
139- . map_err ( |e| Error :: InputOutput ( e. into ( ) ) )
140- }
103+ #[ cfg( all( not( unix) , feature = "tokio" ) ) ]
104+ Transport :: Unix ( _) => Err ( Error :: Unsupported ) ,
105+ #[ cfg( any( unix, not( feature = "tokio" ) ) ) ]
106+ Transport :: Unix ( unix) => unix. connect ( ) . await . map ( Stream :: Unix ) ,
141107
142- #[ cfg( feature = "tokio" ) ]
143- {
144- #[ cfg( unix) ]
145- {
146- tokio:: net:: UnixStream :: from_std ( stream)
147- . map ( Stream :: Unix )
148- . map_err ( |e| Error :: InputOutput ( e. into ( ) ) )
149- }
150-
151- #[ cfg( not( unix) ) ]
152- {
153- let _ = stream;
154- Err ( Error :: Unsupported )
155- }
156- }
157- }
158108 #[ cfg( unix) ]
159109 Transport :: Unixexec ( unixexec) => unixexec. connect ( ) . await . map ( Stream :: Unixexec ) ,
160110 #[ cfg( all( feature = "vsock" , not( feature = "tokio" ) ) ) ]
0 commit comments