File tree 3 files changed +49
-0
lines changed
3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -1707,3 +1707,38 @@ fn test_file_times() {
1707
1707
assert_eq ! ( metadata. created( ) . unwrap( ) , created) ;
1708
1708
}
1709
1709
}
1710
+
1711
+ #[ test]
1712
+ #[ cfg( windows) ]
1713
+ fn windows_unix_socket_exists ( ) {
1714
+ use crate :: sys:: { c, net} ;
1715
+ use crate :: { mem, ptr} ;
1716
+
1717
+ let tmp = tmpdir ( ) ;
1718
+ let socket_path = tmp. join ( "socket" ) ;
1719
+
1720
+ // std doesn't current support Unix sockets on Windows so manually create one here.
1721
+ net:: init ( ) ;
1722
+ unsafe {
1723
+ let socket = c:: WSASocketW (
1724
+ c:: AF_UNIX as i32 ,
1725
+ c:: SOCK_STREAM ,
1726
+ 0 ,
1727
+ ptr:: null_mut ( ) ,
1728
+ 0 ,
1729
+ c:: WSA_FLAG_OVERLAPPED | c:: WSA_FLAG_NO_HANDLE_INHERIT ,
1730
+ ) ;
1731
+ assert_ne ! ( socket, c:: INVALID_SOCKET ) ;
1732
+ let mut addr = c:: SOCKADDR_UN { sun_family : c:: AF_UNIX , sun_path : mem:: zeroed ( ) } ;
1733
+ let bytes = socket_path. as_os_str ( ) . as_encoded_bytes ( ) ;
1734
+ addr. sun_path [ ..bytes. len ( ) ] . copy_from_slice ( bytes) ;
1735
+ let len = mem:: size_of_val ( & addr) as i32 ;
1736
+ let result = c:: bind ( socket, ptr:: addr_of!( addr) . cast :: < c:: SOCKADDR > ( ) , len) ;
1737
+ c:: closesocket ( socket) ;
1738
+ assert_eq ! ( result, 0 ) ;
1739
+ }
1740
+ // Make sure all ways of testing a file exist work for a Unix socket.
1741
+ assert_eq ! ( socket_path. exists( ) , true ) ;
1742
+ assert_eq ! ( socket_path. try_exists( ) . unwrap( ) , true ) ;
1743
+ assert_eq ! ( socket_path. metadata( ) . is_ok( ) , true ) ;
1744
+ }
Original file line number Diff line number Diff line change @@ -1964,6 +1964,7 @@ Windows.Win32.Networking.WinSock.ADDRESS_FAMILY
1964
1964
Windows.Win32.Networking.WinSock.ADDRINFOA
1965
1965
Windows.Win32.Networking.WinSock.AF_INET
1966
1966
Windows.Win32.Networking.WinSock.AF_INET6
1967
+ Windows.Win32.Networking.WinSock.AF_UNIX
1967
1968
Windows.Win32.Networking.WinSock.AF_UNSPEC
1968
1969
Windows.Win32.Networking.WinSock.bind
1969
1970
Windows.Win32.Networking.WinSock.closesocket
@@ -2058,6 +2059,7 @@ Windows.Win32.Networking.WinSock.SOCK_RDM
2058
2059
Windows.Win32.Networking.WinSock.SOCK_SEQPACKET
2059
2060
Windows.Win32.Networking.WinSock.SOCK_STREAM
2060
2061
Windows.Win32.Networking.WinSock.SOCKADDR
2062
+ Windows.Win32.Networking.WinSock.SOCKADDR_UN
2061
2063
Windows.Win32.Networking.WinSock.SOCKET
2062
2064
Windows.Win32.Networking.WinSock.SOCKET_ERROR
2063
2065
Windows.Win32.Networking.WinSock.SOL_SOCKET
Original file line number Diff line number Diff line change @@ -847,6 +847,7 @@ impl ::core::clone::Clone for ADDRINFOA {
847
847
}
848
848
pub const AF_INET : ADDRESS_FAMILY = 2u16 ;
849
849
pub const AF_INET6 : ADDRESS_FAMILY = 23u16 ;
850
+ pub const AF_UNIX : u16 = 1u16 ;
850
851
pub const AF_UNSPEC : ADDRESS_FAMILY = 0u16 ;
851
852
pub const ALL_PROCESSOR_GROUPS : u32 = 65535u32 ;
852
853
#[ repr( C ) ]
@@ -3813,6 +3814,17 @@ impl ::core::clone::Clone for SOCKADDR {
3813
3814
* self
3814
3815
}
3815
3816
}
3817
+ #[ repr( C ) ]
3818
+ pub struct SOCKADDR_UN {
3819
+ pub sun_family : ADDRESS_FAMILY ,
3820
+ pub sun_path : [ u8 ; 108 ] ,
3821
+ }
3822
+ impl :: core:: marker:: Copy for SOCKADDR_UN { }
3823
+ impl :: core:: clone:: Clone for SOCKADDR_UN {
3824
+ fn clone ( & self ) -> Self {
3825
+ * self
3826
+ }
3827
+ }
3816
3828
pub type SOCKET = usize ;
3817
3829
pub const SOCKET_ERROR : i32 = -1i32 ;
3818
3830
pub const SOCK_DGRAM : WINSOCK_SOCKET_TYPE = 2i32 ;
You can’t perform that action at this time.
0 commit comments