Repository navigation
Add exclusive_address and set_exclusive_address - #678
Merged
Thomasdezeeuw merged 2 commits intoOct 18, 2026
Merged
Conversation
Adds Windows only Socket methods for getting and setting SO_EXCLUSIVEADDRUSE, the opposite of SO_REUSEADDR, along with a get/set test. Closes rust-lang#676
Thomasdezeeuw
approved these changes
Oct 17, 2026
| /// prevents other sockets from binding to the same address and port as | ||
| /// this socket, even when they set `SO_REUSEADDR`. Without this option | ||
| /// another socket that sets `SO_REUSEADDR` can bind to the address and port | ||
| /// this socket is bound to and take over its traffic. |
Collaborator
There was a problem hiding this comment.
Can you add that this is only true for Windows?
Contributor
Author
There was a problem hiding this comment.
Done in bf27653, the docs now say the SO_REUSEADDR takeover is Windows behaviour, not Unix. Thanks for the review!
Collaborator
|
Thanks @bhaskargurram-ai |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds Windows only
Socket::exclusive_addressandSocket::set_exclusive_addressfor theSO_EXCLUSIVEADDRUSEoption, the opposite ofSO_REUSEADDR, as suggested in #676: a socket bound without it can have its port taken over by another socket that setsSO_REUSEADDR, and there is currently no way to set the option through socket2 or std.The methods live in the Windows only
impl Socketblock insrc/sys/windows.rsbehind theallfeature, next toset_no_inheritandprotocol, and mirrorreuse_address/set_reuse_address. The getter uses theBoolhelper so both the 1 byte and 4 byte replies Windows gives for boolean options are handled. The docs note that the option has to be set beforebind.Adds a
test!(exclusive_address, set_exclusive_address(true))get/set test gated onall(feature = "all", windows). Checked withcargo check --target x86_64-pc-windows-msvc --features all --all-targets(also with windows-sys pinned to 0.60.2),cargo docwith-D warningsfor that target,cargo test --features all,cargo fmt --checkandcargo clippy --all-targets --features all -- -D warningson Linux.Closes #676