std::os::windows::net: add Unix-domain socket support (AF_UNIX on Windows) #147335
+395
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
r? rust-lang/libs-api
Summary
This PR adds Unix-domain socket support to the Windows port of the standard library,
mirroring the existing APIs in
std::os::unix::net
.The implementation is gated behind the unstable feature
windows_unix_domain_sockets
;track issue #56533 .
Motivation / Background
Windows 10 17063+ officially support AF_UNIX.
Having the same
UnixStream
/UnixListener
surface on Windows removes the need forcrates such as
mio-uds-windows
and lets cross-platform code use a single API.Acknowledgements
99 % of the code was transplanted from
https://github.com/Azure/mio-uds-windows
(thank you @damonbarry ).
The main delta is switching from the
winapi
crate to thestd
.What is added
std::os::windows::net
UnixStream
,UnixListener
,SocketAddr
,sockaddr_un
All types mirror their Unix counterparts and implement the usual
Read+Write
,AsRawSocket/FromRawSocket/IntoRawSocket
,AsSocket
, etc.Feature gate
Testing
Can't run test because rustc ICE
How to try it locally
Notes for reviewers
sys::pal::windows
.unsafe
is restricted toWSASocketW
,bind
,connect
,getsockname
,getpeername
.sockaddr_un
construction follows the Unix implementation: zero-init, copy path, null-term.Drop
impl is reused fromsys::net::Socket
, soclosesocket
always runs.Commit message
Checklist before clicking “Create pull request”
./x.py fmt
– clean./x.py test library/std/tests/net/windows_unix_socket.rs
– blocked./x.py test library/std --stage 1
– blockedBlocked reason:
The bootstrap rustc (stage0) crashes with STATUS_ACCESS_VIOLATION when compiling core during the test phase