@@ -8,8 +8,12 @@ use crate::net::unix::SocketAddr;
8
8
use std:: fmt;
9
9
use std:: io:: { self , Read , Write } ;
10
10
use std:: net:: Shutdown ;
11
+ #[ cfg( target_os = "linux" ) ]
12
+ use std:: os:: linux:: net:: SocketAddrExt ;
13
+ #[ cfg( target_os = "linux" ) ]
14
+ use std:: os:: unix:: ffi:: OsStrExt ;
11
15
use std:: os:: unix:: io:: { AsFd , AsRawFd , BorrowedFd , FromRawFd , IntoRawFd , RawFd } ;
12
- use std:: os:: unix:: net;
16
+ use std:: os:: unix:: net:: { self , SocketAddr as StdSocketAddr } ;
13
17
use std:: path:: Path ;
14
18
use std:: pin:: Pin ;
15
19
use std:: task:: { Context , Poll } ;
@@ -66,7 +70,20 @@ impl UnixStream {
66
70
where
67
71
P : AsRef < Path > ,
68
72
{
69
- let stream = mio:: net:: UnixStream :: connect ( path) ?;
73
+ // On linux, abstract socket paths need to be considered.
74
+ #[ cfg( target_os = "linux" ) ]
75
+ let addr = {
76
+ let os_str_bytes = path. as_ref ( ) . as_os_str ( ) . as_bytes ( ) ;
77
+ if os_str_bytes. starts_with ( b"\0 " ) {
78
+ StdSocketAddr :: from_abstract_name ( os_str_bytes) ?
79
+ } else {
80
+ StdSocketAddr :: from_pathname ( path) ?
81
+ }
82
+ } ;
83
+ #[ cfg( not( target_os = "linux" ) ) ]
84
+ let addr = StdSocketAddr :: from_pathname ( path) ?;
85
+
86
+ let stream = mio:: net:: UnixStream :: connect_addr ( & addr) ?;
70
87
let stream = UnixStream :: new ( stream) ?;
71
88
72
89
poll_fn ( |cx| stream. io . registration ( ) . poll_write_ready ( cx) ) . await ?;
0 commit comments