Skip to content

Special case assume_init for Bool on Windows#655

Open
ChrisDenton wants to merge 1 commit into
rust-lang:masterfrom
ChrisDenton:init-bool
Open

Special case assume_init for Bool on Windows#655
ChrisDenton wants to merge 1 commit into
rust-lang:masterfrom
ChrisDenton:init-bool

Conversation

@ChrisDenton
Copy link
Copy Markdown
Member

On Windows many socket options are documented as having the value "DWORD (boolean)". A DWORD is 4 bytes but when writing a boolean, often only one byte is actually written. While this is mostly consistent, it has been observed that using getsockopt with the IPV6_V6ONLY option can sometimes write 1 byte but other time write 4 bytes. So this PR allows us to accept either 1 or 4 bytes when the type of the option is Bool.

Fixes #564

Comment thread src/sys/windows.rs Outdated
}
}

impl<T: Copy> AssumeInit for T {}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this fakes specialisation by not implementing Copy for the type (i.e. Bool) we want to special case. This is fine for our usage since we only actually need to move values and Bool is private.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other types is this required by? Could we just explicitly implement it for the 3 or 4 other types?

Copy link
Copy Markdown
Member Author

@ChrisDenton ChrisDenton May 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would currently need to be implemented for i32, u32, IN_ADDR, linger and WSAPROTOCOL_INFOW. Which seems fine. My only reluctance was that more things could be added in the future.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider doing that and renaming this to GetsockoptOutput or similar.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

only_v6 panic on windows

2 participants