File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Expand file tree Collapse file tree 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() {
17071707 assert_eq ! ( metadata. created( ) . unwrap( ) , created) ;
17081708 }
17091709}
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
19641964Windows.Win32.Networking.WinSock.ADDRINFOA
19651965Windows.Win32.Networking.WinSock.AF_INET
19661966Windows.Win32.Networking.WinSock.AF_INET6
1967+ Windows.Win32.Networking.WinSock.AF_UNIX
19671968Windows.Win32.Networking.WinSock.AF_UNSPEC
19681969Windows.Win32.Networking.WinSock.bind
19691970Windows.Win32.Networking.WinSock.closesocket
@@ -2058,6 +2059,7 @@ Windows.Win32.Networking.WinSock.SOCK_RDM
20582059Windows.Win32.Networking.WinSock.SOCK_SEQPACKET
20592060Windows.Win32.Networking.WinSock.SOCK_STREAM
20602061Windows.Win32.Networking.WinSock.SOCKADDR
2062+ Windows.Win32.Networking.WinSock.SOCKADDR_UN
20612063Windows.Win32.Networking.WinSock.SOCKET
20622064Windows.Win32.Networking.WinSock.SOCKET_ERROR
20632065Windows.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 {
847847}
848848pub const AF_INET : ADDRESS_FAMILY = 2u16 ;
849849pub const AF_INET6 : ADDRESS_FAMILY = 23u16 ;
850+ pub const AF_UNIX : u16 = 1u16 ;
850851pub const AF_UNSPEC : ADDRESS_FAMILY = 0u16 ;
851852pub const ALL_PROCESSOR_GROUPS : u32 = 65535u32 ;
852853#[ repr( C ) ]
@@ -3813,6 +3814,17 @@ impl ::core::clone::Clone for SOCKADDR {
38133814 * self
38143815 }
38153816}
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+ }
38163828pub type SOCKET = usize ;
38173829pub const SOCKET_ERROR : i32 = -1i32 ;
38183830pub const SOCK_DGRAM : WINSOCK_SOCKET_TYPE = 2i32 ;
You can’t perform that action at this time.
0 commit comments