@@ -9,6 +9,7 @@ use crate::os::cygwin::net::{SocketAddrExt, UnixSocketExt};
99use crate :: os:: linux:: net:: { SocketAddrExt , UnixSocketExt } ;
1010#[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
1111use crate :: os:: unix:: io:: AsRawFd ;
12+ use crate :: path:: Path ;
1213use crate :: test_helpers:: tmpdir;
1314use crate :: thread;
1415use crate :: time:: Duration ;
@@ -22,6 +23,12 @@ macro_rules! or_panic {
2223 } ;
2324}
2425
26+ #[ test]
27+ fn sock_addr_from_pathname ( ) {
28+ let address = or_panic ! ( SocketAddr :: from_pathname( "/path/to/socket" ) ) ;
29+ assert_eq ! ( address. as_pathname( ) , Some ( Path :: new( "/path/to/socket" ) ) ) ;
30+ }
31+
2532#[ test]
2633#[ cfg_attr( target_os = "android" , ignore) ] // Android SELinux rules prevent creating Unix sockets
2734#[ cfg_attr( target_os = "vxworks" , ignore = "Unix sockets are not implemented in VxWorks" ) ]
@@ -32,6 +39,7 @@ fn basic() {
3239 let msg2 = b"world!" ;
3340
3441 let listener = or_panic ! ( UnixListener :: bind( & socket_path) ) ;
42+ assert_eq ! ( Some ( & * socket_path) , listener. local_addr( ) . unwrap( ) . as_pathname( ) ) ;
3543 let thread = thread:: spawn ( move || {
3644 let mut stream = or_panic ! ( listener. accept( ) ) . 0 ;
3745 let mut buf = [ 0 ; 5 ] ;
@@ -79,6 +87,8 @@ fn pair() {
7987 let msg2 = b"world!" ;
8088
8189 let ( mut s1, mut s2) = or_panic ! ( UnixStream :: pair( ) ) ;
90+ assert ! ( s1. local_addr( ) . unwrap( ) . is_unnamed( ) ) ;
91+ assert ! ( s2. peer_addr( ) . unwrap( ) . is_unnamed( ) ) ;
8292 let thread = thread:: spawn ( move || {
8393 // s1 must be moved in or the test will hang!
8494 let mut buf = [ 0 ; 5 ] ;
0 commit comments