diff options
| author | Chris Denton <chris@chrisdenton.dev> | 2023-10-13 05:55:56 +0100 |
|---|---|---|
| committer | Chris Denton <chris@chrisdenton.dev> | 2023-10-13 06:02:38 +0100 |
| commit | 2f5dea09784c5c0dc80b31aea08822a1dc4ecd77 (patch) | |
| tree | 3fc1986a36d5f237973c151bcc70b622eec90d57 /library/std/src/fs | |
| parent | 2b7fe7e0a1665e079683e2c67d2046aa67517519 (diff) | |
| download | rust-2f5dea09784c5c0dc80b31aea08822a1dc4ecd77.tar.gz rust-2f5dea09784c5c0dc80b31aea08822a1dc4ecd77.zip | |
Test that unix sockets exist on Windows
Diffstat (limited to 'library/std/src/fs')
| -rw-r--r-- | library/std/src/fs/tests.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs index d74f0f00e46..f0c4be2327c 100644 --- a/library/std/src/fs/tests.rs +++ b/library/std/src/fs/tests.rs @@ -1707,3 +1707,38 @@ fn test_file_times() { assert_eq!(metadata.created().unwrap(), created); } } + +#[test] +#[cfg(windows)] +fn windows_unix_socket_exists() { + use crate::sys::{c, net}; + use crate::{mem, ptr}; + + let tmp = tmpdir(); + let socket_path = tmp.join("socket"); + + // std doesn't current support Unix sockets on Windows so manually create one here. + net::init(); + unsafe { + let socket = c::WSASocketW( + c::AF_UNIX as i32, + c::SOCK_STREAM, + 0, + ptr::null_mut(), + 0, + c::WSA_FLAG_OVERLAPPED | c::WSA_FLAG_NO_HANDLE_INHERIT, + ); + assert_ne!(socket, c::INVALID_SOCKET); + let mut addr = c::SOCKADDR_UN { sun_family: c::AF_UNIX, sun_path: mem::zeroed() }; + let bytes = socket_path.as_os_str().as_encoded_bytes(); + addr.sun_path[..bytes.len()].copy_from_slice(bytes); + let len = mem::size_of_val(&addr) as i32; + let result = c::bind(socket, ptr::addr_of!(addr).cast::<c::SOCKADDR>(), len); + c::closesocket(socket); + assert_eq!(result, 0); + } + // Make sure all ways of testing a file exist work for a Unix socket. + assert_eq!(socket_path.exists(), true); + assert_eq!(socket_path.try_exists().unwrap(), true); + assert_eq!(socket_path.metadata().is_ok(), true); +} |
